What am I doing wrong to get "Two Entities with different keys are mapped to the same row

See images:

EF Designer

SQL Tables

"Two entities with different keys are mapped to the same row. Ensure these two mapping fragments do not map two groups of entities with overlapping keys to the same group of rows."

In fact, only one of the two (or 6 here) entities will have the key for the single row.

How may I overcome this? SQL View that combines them all to one row? Calculated discriminator column in ContactMethod? How should I have designed the tables differently to work better with EF?

Or is there some XML editing I can do to keep my schema and just tell EF to trust me that I'd never put the same Id in more than one derrived class?

Here's: edmx if it helps.

Upvotes: 0

Views: 3037

Answers (2)

Puzzled
Puzzled

Reputation: 378

The link to edmx file is not work. Perhaps, you have to add a condition tag

<Condition ColumnName="ContactId" IsNull="false" />

to your edmx file using xml-editor:

<AssociationSetMapping Name="FK_Contact_ContactMethod" TypeName="SomeNamespace.FK_Contact_ContactMethod" StoreEntitySet="ContactMethod">
  <EndProperty Name="ContactMethod">
    <ScalarProperty Name="ContactMethodId" ColumnName="ContactMethodId" />
  </EndProperty>
  <EndProperty Name="Contact">
    <ScalarProperty Name="ContactId" ColumnName="ContactId" />
  </EndProperty>
  <Condition ColumnName="ContactId" IsNull="false" />
</AssociationSetMapping>

Upvotes: 3

Taking off the foreign keys to ContactMethod in the database got rid of the errors, but doesn't seem right.

Upvotes: 0

Related Questions