Search code examples
c#entity-frameworkef4-code-only

How Refactor Code/DB schema with EF 4 code first - Data Migration


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:

http://blogs.msdn.com/b/adonet/archive/2010/02/08/entity-designer-database-generation-power-pack.aspx?PageIndex=2#comments

Does anyone have a good strategy for code first?


Solution

  • The EF team have been working on a migrations feature for EF that should solve this problem.

    http://blogs.msdn.com/b/efdesign/archive/2010/10/22/code-first-database-evolution-aka-migrations.aspx

    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