6

In our production environment, we have an automated deploy script that takes down our site, runs migrations, and then brings it back online. We'd like to avoid taking the site down by just switching to the new code when there aren't any migrations that need to be run.

Does entity framework have a command like "Update-Database" that would allow us to check if there are migrations to run?

4

2 回答 2

20

该类DbMigrator具有GetPendingMigrations听起来像您要查找的确切方法的方法。它应该是这样的

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(); 
}
于 2013-07-30T07:07:51.787 回答
4

DbContext.Database.CompatibleWithModel() 与 EF 6.1.3 一起使用

于 2016-01-10T00:35:08.783 回答