实体框架 - 检查待处理迁移 [英] Entity Framework - Check for pending migrations

查看:153
本文介绍了实体框架 - 检查待处理迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的生产环境,我们有一个自动部署脚本,需要了我们的网站,运行迁移,然后把它带回在线。我们希望避免刚切换到新的code采取现场下来的时候有没有那么需要运行任何迁移。

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?

推荐答案

DbMigrator 类有 GetPendingMigrations 方法这听起来像你找一个确切。它应该是这样的。

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(); 
}

这篇关于实体框架 - 检查待处理迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆