实体框架核心自动迁移 [英] EntityFramework Core automatic migrations
本文介绍了实体框架核心自动迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在asp.net核心项目中,是否有任何代码在实体框架核心
代码第一个
中执行自动迁移?
Is there any code to perform automatic migration in Entity Framework core
code first
in asp.net core project?
我只需在MVC4 / 5中添加
I do it simply in MVC4/5 by adding
Database.SetInitializer(new MigrateDatabaseToLatestVersion<AppDbContext, MyProject.Migrations.Configuration>());
public Configuration() {
AutomaticMigrationsEnabled = true;
}
这样可以节省实体更改时间
This saves time when entities changed
推荐答案
您可以在 Startup.cs中调用
context.Database.Migrate()
/ code>
You can call context.Database.Migrate()
in your Startup.cs
例如:
using (var context = new MyContext(...))
{
context.Database.Migrate();
}
这篇关于实体框架核心自动迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文