Entity framework gives you an error when you add foreign key relationships after you already modeled..

The Entity Framework has a lot of nice features in it for mapping relationships. The bugger is its incessant need for the actual foreign key relationships on the database. Unless of course you like editing XML and never want to use the model wizard again.

So you model your database without the foreign keys, deciding “Ill add those later”. You add them and then run the update model wizard. Cool, the relationships appear but the model doesn’t validate.

Error 20 Error 3007: Problem in Mapping Fragments starting at lines 1586, 2100: Non-Primary-Key column(s) [UserID] are being mapped in both fragments to different conceptual side properties - data inconsistency is possible because the corresponding conceptual side properties can be independently modified.
What to do?

It’s actually easy. Just delete the old keys from the entity. ex. You added the Users table relationship. Well, delete the UserID off the entity.

All done.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.