c# - 如何从代码 (EF Core) 应用迁移

标签 c# entity-framework-core entity-framework-migrations

这是一些有效的 EF6 迁移代码:

Database.SetInitializer<CmContext>(null);
var settings = new MigrationsConfiguration();
var migrator = new DbMigrator(settings);
migrator.Update();

使用 EF Core 的等效项是什么?

最佳答案

在 beta 7 及更高版本中,使用:

using Microsoft.Data.Entity;

...

context.Database.Migrate();

关于c# - 如何从代码 (EF Core) 应用迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31710038/

相关文章:

entity-framework - Entity Framework ,代码优先。如何覆盖生成上/下脚本

c# - Entity Framework 无法使用二进制数组添加迁移

c# - 如何使用 MVC 自定义页面错误管理处理 angularjs HTTP 错误?

c# - EF Core 条件(添加)包含到 IQueryable

postgresql - 使用 Entity Framework Core 时自动增量值在 PostgreSQL 中不起作用

c# - Entity Framework Core 和带有存储过程的列级 SQL Server 加密,如何以正确的方式映射属性?

c# - Entity Framework 创建空迁移但坚持认为我的模型不同

c# - 在 Windows 8 应用商店中使用 C# 选择控件时更改边框颜色

c# - 使用BackGroundWorker的错误处理条件失败

c# - LINQ 在两次实现 IEnumerable<T> 时感到困惑