在我们的生产环境中,我们有一个自动化部署脚本,它会关闭我们的网站,运行迁移,然后将其重新上线。我们希望通过在没有需要运行的迁移时切换到新代码来避免关闭网站。
Entity Framework是否有像“Update-Database”这样的命令,可以让我们检查是否有需要运行的迁移?
Entity Framework是否有像“Update-Database”这样的命令,可以让我们检查是否有需要运行的迁移?
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();
}
我使用EF 6.1.3中的DbContext.Database.CompatibleWithModel()
DbContext.Database.CompatibleWithModel()
将返回 true
。这与原始请求不符! - Marcel