Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 using (FacturationEntities context = new FacturationEntities())
            {
                Ville v = new Ville(00000, "Trifouilli les oies");
                Adresse a = new Adresse("33", "rue de la gare", v);
                Assistante ass = new Assistante("Dupont", "Gertrude", a, "123456789012345");
               // context.AddToVilles(v);
               // context.AddToAdresses(a);
                context.AddToAssistante(ass);
                context.SaveChanges();
            }
Avec ce code, quand j'ajoute une assistante, lors de l'insert j'ai également l'insert de l'adresse (et pareil quand j'ajoute une adresse, j'insert automatiquement la ville).
Comment faire pour corriger ça?

Question bonus :

Comment faire de l'héritage avec 1 table/type final. J'ai juste réussi à faire 1 table pour le parent abstrait et 1 table/enfant.

Je joins également l'edmx s'il faut corrigé quelque chose dedans.

Merci d'avance

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
  <!-- EF Runtime content -->
  <edmx:Runtime>
    <!-- SSDL content -->
    <edmx:StorageModels>
    <Schema Namespace="facturationModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2005" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">
        <EntityContainer Name="facturationModelStoreContainer">
          <EntitySet Name="Adresse" EntityType="facturationModel.Store.Adresse" store:Type="Tables" Schema="dbo" />
          <EntitySet Name="Assistante" EntityType="facturationModel.Store.Assistante" store:Type="Tables" Schema="dbo" />
          <EntitySet Name="Ville" EntityType="facturationModel.Store.Ville" store:Type="Tables" Schema="dbo" />
          <AssociationSet Name="FK_Adresse_Ville" Association="facturationModel.Store.FK_Adresse_Ville">
            <End Role="Ville" EntitySet="Ville" />
            <End Role="Adresse" EntitySet="Adresse" />
          </AssociationSet>
          <AssociationSet Name="FK_AssistanteAdresse" Association="facturationModel.Store.FK_AssistanteAdresse">
            <End Role="Adresse" EntitySet="Adresse" />
            <End Role="Assistante" EntitySet="Assistante" />
          </AssociationSet>
        </EntityContainer>
        <EntityType Name="Adresse">
          <Key>
            <PropertyRef Name="IdAdresse" />
          </Key>
          <Property Name="IdAdresse" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
          <Property Name="Numero" Type="nvarchar" Nullable="false" MaxLength="5" />
          <Property Name="Rue" Type="nvarchar" Nullable="false" MaxLength="40" />
          <Property Name="IdVille" Type="int" Nullable="false" />
        </EntityType>
        <EntityType Name="Assistante">
          <Key>
            <PropertyRef Name="IdAssistante" />
          </Key>
          <Property Name="IdAssistante" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
          <Property Name="Nom" Type="nvarchar(max)" Nullable="false" />
          <Property Name="Prenom" Type="nvarchar(max)" Nullable="false" />
          <Property Name="NumeroSecu" Type="nvarchar" Nullable="false" MaxLength="15" />
          <Property Name="IdAdresse" Type="int" Nullable="false" />
        </EntityType>
        <EntityType Name="Ville">
          <Key>
            <PropertyRef Name="IdVille" />
          </Key>
          <Property Name="IdVille" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
          <Property Name="Commune" Type="nvarchar" Nullable="false" MaxLength="50" />
          <Property Name="CodePostal" Type="int" Nullable="false" />
        </EntityType>
        <Association Name="FK_Adresse_Ville">
          <End Role="Ville" Type="facturationModel.Store.Ville" Multiplicity="1" />
          <End Role="Adresse" Type="facturationModel.Store.Adresse" Multiplicity="*" />
          <ReferentialConstraint>
            <Principal Role="Ville">
              <PropertyRef Name="IdVille" />
            </Principal>
            <Dependent Role="Adresse">
              <PropertyRef Name="IdVille" />
            </Dependent>
          </ReferentialConstraint>
        </Association>
        <Association Name="FK_AssistanteAdresse">
          <End Role="Adresse" Type="facturationModel.Store.Adresse" Multiplicity="1" />
          <End Role="Assistante" Type="facturationModel.Store.Assistante" Multiplicity="*" />
          <ReferentialConstraint>
            <Principal Role="Adresse">
              <PropertyRef Name="IdAdresse" />
            </Principal>
            <Dependent Role="Assistante">
              <PropertyRef Name="IdAdresse" />
            </Dependent>
          </ReferentialConstraint>
        </Association>
      </Schema></edmx:StorageModels>
    <!-- CSDL content -->
    <edmx:ConceptualModels>
      <Schema Namespace="facturationModel" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2006/04/edm">
        <EntityContainer Name="FacturationEntities">
          <EntitySet Name="Adresses" EntityType="facturationModel.Adresse" />
          <EntitySet Name="Villes" EntityType="facturationModel.Ville" />
          <AssociationSet Name="FK_Adresse_Ville" Association="facturationModel.FK_Adresse_Ville">
            <End Role="Ville" EntitySet="Villes" />
            <End Role="Adresse" EntitySet="Adresses" />
          </AssociationSet>
          <EntitySet Name="Assistante" EntityType="facturationModel.Assistante" />
          <AssociationSet Name="FK_AssistanteAdresse" Association="facturationModel.FK_AssistanteAdresse">
            <End Role="Adresse" EntitySet="Adresses" />
            <End Role="Assistante" EntitySet="Assistante" />
          </AssociationSet>
        </EntityContainer>
        <EntityType Name="Adresse">
          <Key>
            <PropertyRef Name="IdAdresse" />
          </Key>
          <Property Type="Int32" Name="IdAdresse" Nullable="false" annotation:StoreGeneratedPattern="Identity" a:SetterAccess="Private" xmlns:a="http://schemas.microsoft.com/ado/2006/04/codegeneration" />
          <Property Type="String" Name="Numero" Nullable="false" MaxLength="5" FixedLength="false" Unicode="true" />
          <Property Type="String" Name="Rue" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true" />
          <NavigationProperty Name="Ville" Relationship="facturationModel.FK_Adresse_Ville" FromRole="Adresse" ToRole="Ville" a:SetterAccess="Private" xmlns:a="http://schemas.microsoft.com/ado/2006/04/codegeneration" a:GetterAccess="Private" />
          <NavigationProperty Name="Assistante" Relationship="facturationModel.FK_AssistanteAdresse" FromRole="Adresse" ToRole="Assistante" a:GetterAccess="Internal" xmlns:a="http://schemas.microsoft.com/ado/2006/04/codegeneration" a:SetterAccess="Internal" />
        </EntityType>
        <EntityType Name="Ville">
          <Key>
            <PropertyRef Name="IdVille" />
          </Key>
          <Property Type="Int32" Name="IdVille" Nullable="false" annotation:StoreGeneratedPattern="Identity" a:SetterAccess="Private" xmlns:a="http://schemas.microsoft.com/ado/2006/04/codegeneration" />
          <Property Type="String" Name="Commune" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
          <Property Type="Int32" Name="CodePostal" Nullable="false" />
          <NavigationProperty Name="Adresses" Relationship="facturationModel.FK_Adresse_Ville" FromRole="Ville" ToRole="Adresse" a:SetterAccess="Private" xmlns:a="http://schemas.microsoft.com/ado/2006/04/codegeneration" />
        </EntityType>
        <Association Name="FK_Adresse_Ville">
          <End Type="facturationModel.Ville" Role="Ville" Multiplicity="1" />
          <End Type="facturationModel.Adresse" Role="Adresse" Multiplicity="*" />
        </Association>
        <EntityType Name="Assistante">
          <Key>
            <PropertyRef Name="IdAssistante" />
          </Key>
          <Property Type="Int32" Name="IdAssistante" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
          <Property Type="String" Name="Nom" Nullable="false" MaxLength="Max" FixedLength="false" Unicode="true" />
          <Property Type="String" Name="Prenom" Nullable="false" MaxLength="Max" FixedLength="false" Unicode="true" />
          <Property Type="String" Name="NumeroSecu" Nullable="false" MaxLength="15" FixedLength="false" Unicode="true" />
          <NavigationProperty Name="Adresse" Relationship="facturationModel.FK_AssistanteAdresse" FromRole="Assistante" ToRole="Adresse" />
        </EntityType>
        <Association Name="FK_AssistanteAdresse">
          <End Type="facturationModel.Adresse" Role="Adresse" Multiplicity="1" />
          <End Type="facturationModel.Assistante" Role="Assistante" Multiplicity="0..1" />
        </Association>
      </Schema>
    </edmx:ConceptualModels>
    <!-- C-S mapping content -->
    <edmx:Mappings>
      <Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">
        <EntityContainerMapping StorageEntityContainer="facturationModelStoreContainer" CdmEntityContainer="FacturationEntities">
          <EntitySetMapping Name="Adresses">
            <EntityTypeMapping TypeName="facturationModel.Adresse">
              <MappingFragment StoreEntitySet="Adresse">
                <ScalarProperty Name="Rue" ColumnName="Rue" />
                <ScalarProperty Name="Numero" ColumnName="Numero" />
                <ScalarProperty Name="IdAdresse" ColumnName="IdAdresse" />
              </MappingFragment>
            </EntityTypeMapping>
          </EntitySetMapping>
          <EntitySetMapping Name="Villes">
            <EntityTypeMapping TypeName="facturationModel.Ville">
              <MappingFragment StoreEntitySet="Ville">
                <ScalarProperty Name="CodePostal" ColumnName="CodePostal" />
                <ScalarProperty Name="Commune" ColumnName="Commune" />
                <ScalarProperty Name="IdVille" ColumnName="IdVille" />
              </MappingFragment>
            </EntityTypeMapping>
          </EntitySetMapping>
          <AssociationSetMapping Name="FK_Adresse_Ville" TypeName="facturationModel.FK_Adresse_Ville" StoreEntitySet="Adresse">
            <EndProperty Name="Adresse">
              <ScalarProperty Name="IdAdresse" ColumnName="IdAdresse" />
            </EndProperty>
            <EndProperty Name="Ville">
              <ScalarProperty Name="IdVille" ColumnName="IdVille" />
            </EndProperty>
          </AssociationSetMapping>
          <EntitySetMapping Name="Assistante">
            <EntityTypeMapping TypeName="facturationModel.Assistante">
              <MappingFragment StoreEntitySet="Assistante">
                <ScalarProperty Name="NumeroSecu" ColumnName="NumeroSecu" />
                <ScalarProperty Name="Prenom" ColumnName="Prenom" />
                <ScalarProperty Name="Nom" ColumnName="Nom" />
                <ScalarProperty Name="IdAssistante" ColumnName="IdAssistante" />
              </MappingFragment>
            </EntityTypeMapping>
          </EntitySetMapping>
          <AssociationSetMapping Name="FK_AssistanteAdresse" TypeName="facturationModel.FK_AssistanteAdresse" StoreEntitySet="Assistante">
            <EndProperty Name="Assistante">
              <ScalarProperty Name="IdAssistante" ColumnName="IdAssistante" />
            </EndProperty>
            <EndProperty Name="Adresse">
              <ScalarProperty Name="IdAdresse" ColumnName="IdAdresse" />
            </EndProperty>
            <Condition ColumnName="IdAdresse" IsNull="false" />
          </AssociationSetMapping>
          </EntityContainerMapping>
      </Mapping>
    </edmx:Mappings>
  </edmx:Runtime>
  <!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
  <Designer xmlns="http://schemas.microsoft.com/ado/2007/06/edmx">
    <Connection>
      <DesignerInfoPropertySet>
        <DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
      </DesignerInfoPropertySet>
    </Connection>
    <Options>
      <DesignerInfoPropertySet>
        <DesignerProperty Name="ValidateOnBuild" Value="true" />
        <DesignerProperty Name="EnablePluralization" Value="False" />
        <DesignerProperty Name="IncludeForeignKeysInModel" Value="False" />
      </DesignerInfoPropertySet>
    </Options>
    <!-- Diagram content (shape and connector positions) -->
    <Diagrams>
      <Diagram Name="Model">
        <EntityTypeShape EntityType="facturationModel.Adresse" Width="1.5" PointX="3" PointY="0.875" Height="1.7879850260416665" />
        <EntityTypeShape EntityType="facturationModel.Ville" Width="1.5" PointX="0.75" PointY="0.875" Height="1.7879850260416677" />
        <AssociationConnector Association="facturationModel.FK_Adresse_Ville" >
          <ConnectorPoint PointX="2.25" PointY="1.7689925130208337" />
          <ConnectorPoint PointX="3" PointY="1.7689925130208337" />
        </AssociationConnector>
        <EntityTypeShape EntityType="facturationModel.Assistante" Width="1.5" PointX="5.25" PointY="0.875" Height="1.9802864583333319" />
        <AssociationConnector Association="facturationModel.FK_AssistanteAdresse" >
          <ConnectorPoint PointX="4.5" PointY="1.8651432291666659" />
          <ConnectorPoint PointX="5.25" PointY="1.8651432291666659" />
        </AssociationConnector>
      </Diagram>
    </Diagrams>
  </Designer>
</edmx:Edmx>