Reputation: 3093
What are the best practices for database refactoring with codefirst EF4?
I am interested to hear how people change the classes and the database when the RecreateDatabaseIfModelChanges option is not feasible. Migration of data will need to occur.
Currently Microsoft has a solution for doing this with model first:
Does anyone have a good strategy for code first?
Upvotes: 7
Views: 1476
Reputation: 89200
The EF team have been working on a migrations feature for EF that should solve this problem.
Scott Gu said on his recent tour around Europe that they should be releasing this feature soon. I'm holding my breath.
EXCITING UPDATE:
This has now been released as a CTP: http://blogs.msdn.com/b/adonet/archive/2011/07/27/code-first-migrations-august-2011-ctp-released.aspx
Upvotes: 1
Reputation: 27813
In my CodeFirst application, local builds have a app.config flag that denotes not being in production. When I'm not in production it completely nukes and recreates the database. Since my production database user does NOT have permissions to drop the database even if my web.config transform is missed somehow (thus EF tries to recreate the database) my production database will not be deleted, and instead an exception will be thrown.
My workflow goes like this:
Step #2 automatically creates a new, clean database based on the latest data model so I always know I have an up to date database that doesn't have artifacts from development efforts that may not be production ready yet.
Upvotes: 1
Reputation: 38408
I am working on database context initializer which will notify webmaster if model and db schema are out of sync and will show what differs. This can by useful for developers who prefer to have complete control both over code-first model and database schema. Check it out:
https://github.com/rialib/efextensions
Upvotes: 1