Entity Framework - checking pending migrations

In our production environment, we have an automatic deployment script that deletes our site, starts the migration, and then returns it online. We would like to avoid going to the site simply by switching to a new code when there are no migrations to be started.

Does the entity’s infrastructure have a command such as Update-Database that will allow us to check whether there are migrations to run?

+3
c # asp.net-mvc entity-framework
Jul 29 '13 at 19:10
source share
2 answers

The DbMigrator class has a GetPendingMigrations method that sounds like the exact one you are looking for. It should be something like

 YourMigrationsConfiguration cfg = new YourMigrationsConfiguration(); cfg.TargetDatabase = new DbConnectionInfo( theConnectionString, "provider" ); DbMigrator dbMigrator = new DbMigrator( cfg ); if ( dbMigrator.GetPendingMigrations().Any() ) { // there are pending migrations // do whatever you want, for example dbMigrator.Update(); } 
+13
Jul 30 '13 at 7:07
source share

I am using DbContext.Database.CompatibleWithModel() with EF 6.1.3

+3
Jan 10 '16 at 0:35
source share



All Articles