After updating the edmx model, how about a DbContext?

I just started using EF5. I created the MSSQL database, then created a model file (edmx), and then used the "Add Code Generation Element" to create the EF5 dbcontext classes.

Whenever I change my database (adding a column or changing a data type), I see that the β€œupdate model from the database” does not work, and I need to delete and recreate the model. this is fine for me, but what happens to my dbcontext classes generated from the model.tt template model.tt ? Do I also need to generate all the dbcontext classes dbcontext ?

what is the right way to work with the database - the first environment and keep the .edmx and dbcontext in sync with the database?

+4
source share
3 answers

After you update your model from the database, try the Run Custom Tool Entity Model, it works and is tested for me.

from Entity Model β†’ Right Click β†’ Run Custom Tool

+4
source

I could see two ways to do this:

1) Use the EF4 approach (which is also possible with EF5), which uses the edmx stream and databases. Then, whenever you have changes to your database, you simply "update your model from the database .." from the context menu of the edmx designer. This automatically updates your generated entity classes.

2) Use the EF5 approach - generate your POCO classes once, do not use edmx at all. You can do this using Entity Framework Power Tools, and then use Engineer Reverse Code First. Manually apply changes in their classes when changing the database model (which, obviously, will only work with incremental database changes).

+1
source

In VS2010, there is a button in the upper right corner of the solution developer called "Convert All Templates" that updates the classes you created

0
source

All Articles