Reputation: 4262
I just started using EF5. I created a MSSQL database, then I created the model (edmx) file and then used the "Add code generation item" to create EF5 dbcontext
classes.
Whenever I alter my database (adding a column or changing a datatype) I see that "update model from database" doesn't work and I need to delete and recreate the model.
that's ok for me but what happens to my DbContext
classes generated from the model.tt
template file? do I have to generate all the DbContext
classes again also?
what's the correct way to work with a database-first environment and keep the .edmx
model and the DbContext
classes in sync with the database?
Upvotes: 4
Views: 2762
Reputation: 6373
I could see two ways of doing it:
1) Use EF4 approach (that should be possible with EF5 too) that is use edmx and database first flow. Then whenever you have changes in your database, you just "Update Your Model from Database.." from edmx designer context-menu. That automatically updates your generated entity classes.
2) Use EF5 approach - Generate your POCO classes one time, do not use edmx at all. You can do this by using Entity Framework Power Tools and then use "Reverse Engineer Code First". Apply manually changes to your classes when database model changes (that obviously would work only with incremental database changes).
Upvotes: 1
Reputation: 7082
After you update your model from database, try to Run Custom Tool
the Entity Model, works and tested for me.
from Entity Model
→ Right Click → Run Custom Tool
Upvotes: 4
Reputation: 5865
In VS2010 there is a button at the very right top of the solution explorer called "Transform all templates" which update your generated classes
Upvotes: 0