James
James

Reputation: 2610

Automatic Migration vs Code-base Migration

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!

Upvotes: 21

Views: 13952

Answers (2)

Vladislav Kostenko
Vladislav Kostenko

Reputation: 1205

There is more info about your question at MSDN. They don't recommend to mix automatic and code based migrations in team development scenarios. But I don't understand clearly what problems it can create.

Upvotes: -2

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364249

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.

Upvotes: 24

Related Questions