Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic Migration vs Code-base Migration

Tags:

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!

like image 525
James Avatar asked May 30 '12 05:05

James


1 Answers

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.

like image 53
Ladislav Mrnka Avatar answered Oct 02 '22 11:10

Ladislav Mrnka