Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 6 - Entity classes get deleted when updating edmx, why is that? and what can I do to stop it?

When updating the entity framework diagram using the EDMX Designer, sometimes the entities under the model.TT file get deleted and I then have to undo the changes in Source Control.

What is the reason for this and what can I do to stop this from happening?

like image 979
ashcharlton Avatar asked May 22 '15 12:05

ashcharlton


People also ask

How do I Update EDMX entity framework?

In the Model Browser, right-click the . edmx file and select Update Model from Database. Expand the Tables, Views, and Stored Procedures nodes, and check the objects you want to add to the . edmx file.

How do I Update my database from EDMX?

Right-click on the designer surface of the EDMX and click Update Model From Database. Now, right-click and select "Update Model from Database" to recreate the entire model again.

What is EDMX file in Entity Framework?

An . edmx file is an XML file that defines an Entity Data Model (EDM), describes the target database schema, and defines the mapping between the EDM and the database. An . edmx file also contains information that is used by the ADO.NET Entity Data Model Designer (Entity Designer) to render a model graphically.


1 Answers

I had the same problem one year ago. As far as I know, it's a bug that happens when you have some strange/redundant relationship in your database. Entity Framework loses its mind while updating the classes.

Delete your model, and create it without the last table you created. If this does not work, try to re-create with just a few tables ... keep updating the table by table until you find the one that is causing the problem.

Keep in mind that Database-first model (with EDMX) is "practically deprecated", EF 7 does not support it anymore. More information: http://blogs.msdn.com/b/adonet/archive/2014/10/21/ef7-what-does-code-first-only-really-mean.aspx

Hope it helps!

like image 121
Fabio Luz Avatar answered Oct 21 '22 02:10

Fabio Luz