Entity Framework - Check for pending migrations

前端 未结 2 1595
没有蜡笔的小新
没有蜡笔的小新 2020-12-18 08:01

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 s

相关标签:
2条回答
  • 2020-12-18 08:30

    The DbMigrator class has the GetPendingMigrations method which sounds like the exact one you look 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(); 
    }
    
    0 讨论(0)
  • 2020-12-18 08:32

    I use DbContext.Database.CompatibleWithModel() with EF 6.1.3

    0 讨论(0)
提交回复
热议问题