I am using Entity Framework and I ran into an odd build error.
I am building a forum and I set up a table in the database for "ignores" when people don't like each other they will ignore someone. The table has two columns and together they are the primary keys.
PK InitiatingUser
PK IgnoredUser
When EF maps this table I get this error:
Error 7 Error 3034: Problem in mapping fragments starting at lines 1467, 1477:Two entities with possibly different keys are mapped to the same row. Ensure these two mapping fragments map both ends of the AssociationSet to the corresponding columns.
I opened up the edmx in the XML editor and navigated to the offending lines.
<MappingFragment StoreEntitySet="Ignores">
<ScalarProperty Name="IgnoredUser" ColumnName="IgnoredUser" />
<ScalarProperty Name="InitiatingUser" ColumnName="InitiatingUser" />
</MappingFragment>
I am just getting started with EF and I don't understand what is going on or what the issue might be.
The relationships between ignores used to have foreign keys mapping both initiating user and ignored user to the primary key (username) of users table. That was how it was when I first mapped EF to this table. I have since deleted the FKs to see if that would help but it didn't.
This is likely due to including a many-to-many join table in your entity model, or what EF thinks is such a table (possibly such as one that doesn't have its own self-contained key, but whose identity is made up of two or more foreign keys).
So, for example, let's say you have the following tables:
In your entity model, you should only add Person and Address. If you add PersonAddress, then EF will throw the error. According to this MSDN Q&A, EF will take the join table into account automatically.
I don't know what was wrong here, but I just deleted the table from the ORM and the DB then recreated it with an actual ID column, instead of two primary keys. I re-mapped the table, compiled, and all is well now. It would have been convenient to do it the way I had it, but oh well.
If anyone has any insight let me know. I'd rather accept someone else's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With