Defining an Entity Framework 1:1 association
Posted
by Craig Fisher
on Stack Overflow
See other posts from Stack Overflow
or by Craig Fisher
Published on 2009-01-24T00:09:27Z
Indexed on
2010/04/29
9:17 UTC
Read the original article
Hit count: 729
I'm trying to define a 1:1 association between two entities (one maps to a table and the other to a view - using DefinedQuery) in an Entity Framework model. When trying to define the mapping for this in the designer, it makes me choose the (1) table or view to map the association to. What am I supposed to choose? I can choose either of the two tables but then I am forced to choose a column from that table (or view) for each end of the relationship. I would expect to be able to choose a column from one table for one end of the association and a column from the other table for the other end of the association, but there's no way to do this. Here I've chosen to map to the "DW_ WF_ClaimInfo" view and it is forcing me to choose two columns from that view - one for each end of the relationship.
I've also tried defining the mapping manually in the XML as follows:
<AssociationSetMapping Name="Entity1Entity2" TypeName="ClaimsModel.Entity1Entity2"
StoreEntitySet="Entity1">
<EndProperty Name="Entity2">
<ScalarProperty Name="DOCUMENT" ColumnName="DOCUMENT" />
</EndProperty>
<EndProperty Name="Entity1">
<ScalarProperty Name="PK_DocumentId" ColumnName="PK_DocumentId" />
</EndProperty>
</AssociationSetMapping>
But this gives: Error 2010: The Column 'DOCUMENT' specified as part of this MSL does not exist in MetadataWorkspace. Seems like it still expects both columns to come from the same table, which doesn't make sense to me.
Furthermore, if I select the same key for each end, e.g.:
<AssociationSetMapping Name="Entity1Entity2" TypeName="ClaimsModel.Entity1Entity2"
StoreEntitySet="Entity1">
<EndProperty Name="Entity2">
<ScalarProperty Name="DOCUMENT" ColumnName="PK_DocumentId" />
</EndProperty>
<EndProperty Name="Entity1">
<ScalarProperty Name="PK_DocumentId" ColumnName="PK_DocumentId" />
</EndProperty>
</AssociationSetMapping>
I then get:
Error 3021: Problem in Mapping Fragment starting at line 675: Each of the following
columns in table AssignedClaims is mapped to multiple conceptual side properties:
AssignedClaims.PK_DocumentId is mapped to
<AssignedClaimDW_WF_ClaimInfo.DW_WF_ClaimInfo.DOCUMENT,
AssignedClaimDW_WF_ClaimInfo.AssignedClaim.PK_DocumentId>
What am I not getting?
© Stack Overflow or respective owner