Reputation: 179
I am trying to update my edmx, RIGHT CLICK -> UPDATE MODEL FROM DATABASE. And each time i try to update error appear "An entry with the same key already exists
Can some buddy please help?
Upvotes: 3
Views: 12087
Reputation: 8104
Note that EDMX approach will be deprecated in Entity Framework 7:
“Update model from database” is a process that allows you to incrementally pull additional database objects (or changes to existing database objects) into your EDMX model. Unfortunately the implementation of this feature wasn’t great and you would often end up losing customizations you had made to the model, or having to manually fix-up some of the changes the wizard tried to apply (often dropping to hand editing the xml).
For Code First you can re-run the reverse engineer process and have it regenerate your model. This works fine in basic scenarios, but you have to be careful how you customize the model otherwise your changes will get reverted when the code is re-generated. There are some customizations that are difficult to apply without editing the scaffolded code.
So the recommended approach for EF 7 is to do reverse engineering of database into code, not into edmx, something called code second approach before.
Upvotes: 0
Reputation: 953
Sometimes the duplicate might not be shown in the edmx diagram, it could the code side. EF can get a little messy sometimes but not too good in dealing with those loop holes.
As an addition to Fernanda's suggestion, the cleanest way is to delete your edmx file and reconfigure the connection string again.
in case you don't want to do that, you can delete all tables & functions in your edmx, save it and see if the same error still occur. If the same error don't occur anymore, re-add everything and save it.
Upvotes: 6