次の表を含むEntityFramework5ModelFirstプロジェクトがあります。
Extension
Id : Int32, PK
Number: String
User
Id: Int32, PK
Name: String
UserExtensionMap
UserId : Int32 (FK -> User.Id), PK
ExtensionId : Int32 (FK -> Extension.Id), PK
上記のテーブルと関連付けをUserExtensionMapに設定すると、UserIdとExtensionIdがマップされていないというエラーが表示されます。
そこで、UserExtensionMapテーブルを右クリックして、テーブルマッピングを選択すると、次の画面が表示されます。
マップを設定できますが、Extensions.NumberとUser.Usernameをマップするものはありません-混乱していますUsers.Id to UserExtensionUser.Id
!Extensions.Id to UserExtension.ExtensionId
コンパイルしようとするとエラーが発生します:
Error 3024: Problem in mapping fragments starting at line 119:Must specify mapping for all key properties (UserExtensionMaps.ExtensionId, UserExtensionMaps.UserId) of the EntitySet UserExtensionMaps.
UserExtensionMapの上記のマップを削除すると、次のエラーが発生します。
Error 3027: No mapping specified for the following EntitySet/AssociationSet - UserExtensionMaps.
私のモデルXMLファイルは以下のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="3.0" xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx">
<!-- EF Runtime content -->
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="Server.Store" Alias="Self" Provider="System.Data.SqlServerCe.4.0" ProviderManifestToken="4.0" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
<EntityContainer Name="ServerStoreContainer">
<EntitySet Name="Users" EntityType="Server.Store.Users" store:Type="Tables" Schema="dbo" />
<EntitySet Name="Extensions" EntityType="Server.Store.Extensions" store:Type="Tables" Schema="dbo" />
</EntityContainer>
<EntityType Name="Users">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
<Property Name="Username" Type="nvarchar" Nullable="false" />
</EntityType>
<EntityType Name="Extensions">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
<Property Name="Number" Type="nvarchar" Nullable="false" />
</EntityType>
</Schema></edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
<Schema Namespace="Server" Alias="Self" p1:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:p1="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
<EntityContainer Name="ServerEntities" p1:LazyLoadingEnabled="true" >
<EntitySet Name="Users" EntityType="Server.User" />
<EntitySet Name="Extensions" EntityType="Server.Extension" />
<EntitySet Name="UserExtensionMaps" EntityType="Server.UserExtensionMap" />
<AssociationSet Name="ExtensionUserExtensionMap" Association="Server.ExtensionUserExtensionMap">
<End Role="Extension" EntitySet="Extensions" />
<End Role="UserExtensionMap" EntitySet="UserExtensionMaps" />
</AssociationSet>
<AssociationSet Name="UserUserExtensionMap" Association="Server.UserUserExtensionMap">
<End Role="User" EntitySet="Users" />
<End Role="UserExtensionMap" EntitySet="UserExtensionMaps" />
</AssociationSet>
</EntityContainer>
<EntityType Name="User">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Type="Int32" Name="Id" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Type="String" Name="Username" Nullable="false" />
<NavigationProperty Name="UserExtensionMaps" Relationship="Server.UserUserExtensionMap" FromRole="User" ToRole="UserExtensionMap" />
</EntityType>
<EntityType Name="Extension">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Type="Int32" Name="Id" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Type="String" Name="Number" Nullable="false" />
<NavigationProperty Name="UserExtensionMaps" Relationship="Server.ExtensionUserExtensionMap" FromRole="Extension" ToRole="UserExtensionMap" />
</EntityType>
<EntityType Name="UserExtensionMap" >
<Key>
<PropertyRef Name="ExtensionId" />
<PropertyRef Name="UserId" />
</Key>
<NavigationProperty Name="Extension" Relationship="Server.ExtensionUserExtensionMap" FromRole="UserExtensionMap" ToRole="Extension" />
<Property Type="Int32" Name="ExtensionId" Nullable="false" />
<NavigationProperty Name="User" Relationship="Server.UserUserExtensionMap" FromRole="UserExtensionMap" ToRole="User" />
<Property Type="Int32" Name="UserId" Nullable="false" />
</EntityType>
<Association Name="ExtensionUserExtensionMap">
<End Type="Server.Extension" Role="Extension" Multiplicity="1" />
<End Type="Server.UserExtensionMap" Role="UserExtensionMap" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="Extension">
<PropertyRef Name="Id" />
</Principal>
<Dependent Role="UserExtensionMap">
<PropertyRef Name="ExtensionId" />
</Dependent>
</ReferentialConstraint>
</Association>
<Association Name="UserUserExtensionMap">
<End Type="Server.User" Role="User" Multiplicity="1" />
<End Type="Server.UserExtensionMap" Role="UserExtensionMap" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="User">
<PropertyRef Name="Id" />
</Principal>
<Dependent Role="UserExtensionMap">
<PropertyRef Name="UserId" />
</Dependent>
</ReferentialConstraint>
</Association>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs">
<EntityContainerMapping StorageEntityContainer="ServerStoreContainer" CdmEntityContainer="ServerEntities">
<EntitySetMapping Name="Users">
<EntityTypeMapping TypeName="IsTypeOf(Server.User)">
<MappingFragment StoreEntitySet="Users">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="Username" ColumnName="Username" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<EntitySetMapping Name="Extensions">
<EntityTypeMapping TypeName="IsTypeOf(Server.Extension)">
<MappingFragment StoreEntitySet="Extensions">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="Number" ColumnName="Number" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
</EntityContainerMapping>
</Mapping></edmx:Mappings>
</edmx:Runtime>
<!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
<Designer xmlns="http://schemas.microsoft.com/ado/2009/11/edmx">
<Connection>
<DesignerInfoPropertySet>
<DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
</DesignerInfoPropertySet>
</Connection>
<Options>
<DesignerInfoPropertySet>
<DesignerProperty Name="ValidateOnBuild" Value="true" />
<DesignerProperty Name="EnablePluralization" Value="True" />
<DesignerProperty Name="IncludeForeignKeysInModel" Value="True" />
<DesignerProperty Name="CodeGenerationStrategy" Value="None" />
</DesignerInfoPropertySet>
</Options>
<!-- Diagram content (shape and connector positions) -->
<Diagrams></Diagrams>
</Designer>
</edmx:Edmx>