Entity framework 4.3 run migrations at application start

Sly picture Sly · Feb 14, 2012 · Viewed 14.9k times · Source

What is the best way to execute all required db migrations at application start with EF 4.3?

Answer

Ladislav Mrnka picture Ladislav Mrnka · Feb 14, 2012

The best way should be using new MigrateDatabaseToLatestVersion initializer.

Database.SetInitializer<YourContext>(
    new MigrateDatabaseToLatestVersion<YourContext, YourMigrationsConfig>());
Database.Initialize(false);