Code-base Migration vs. Automatic Migration

ef-migrations entity-framework

Question

I'm learning EF4.3 Migration, and I have read these two articles from ado.net team blog:

http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx

http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx

But after reading this two articles, I still not clear what's the difference between them and when to use code-based migraion, when to use automatic migration. Anyone can guide me?

Thanks!

1
20
5/30/2012 9:04:43 AM

Accepted Answer

Those articles are very clear so if you don't understand the difference it means that you didn't concentrate while reading the text and you also probably didn't follow the text by coding examples yourselves.

Automatic migration is just a magic tool. You run your application and you will always get your database in the latest version because EF will do implicit migration every time it is needed - in the purest version you never need to do anything more than enabling automatic migrations.

Automatic migrations are sometimes not enough. You need to add some customization to migration code or run some additional SQL commands for example to transform data. In such case you add explicit code based migration by calling Add-Migration command. Explicit migration shows all migration code which will be executed during migration (there is no additional magic).

If you turn off automatic migrations you must always define explicit migration to define database upgrading process in well defined explicit steps. This is especially useful for scenarios where you need to use both upgrading and downgrading to specific version.

22
5/30/2012 9:04:34 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow