entity framework – 检查挂起的迁移
在我们的生产环境中,我们有一个自动部署脚本,用于关闭我们的站点,运行迁移,然后将其重新联机。 我们希望避免在没有任何需要运行的迁移时切换到新代码来关闭网站。
entity framework是否有像“Update-Database”这样的命令,可以让我们检查是否有要运行的迁移?
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(); }
我将DbContext.Database.CompatibleWithModel()
与EF 6.1.3一起使用
- 根据一组关键字进行搜索
- 违反类型的inheritance安全规则:’MySql.Data.Entity.MySqlEFConfiguration’
- ASP.NET MVC和Angularjs一起+ ASP.NET Web API
- 剃刀中的多个复选框(使用foreach)
- 如何在mvc 4的web.config文件中添加程序集
- Google .NET API – 除FileDataStore之外的任何其他DataStore?
- 如何在MVC中创建foreach循环以为项设置新值。
- MVC SiteMap从menuhelper隐藏节点,但在sitepathhelper中显示(breadcrumbs)
- 将多个属性的组validation消息一起组成一个消息asp.net mvc