EntityFramework Core 自动迁移 [英] EntityFramework Core automatic migrations
本文介绍了EntityFramework Core 自动迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
asp.net core项目中的Entity Framework core
code first
中是否有执行自动迁移的代码?
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
例如:
using (var context = new MyContext(...))
{
context.Database.Migrate();
}
这篇关于EntityFramework Core 自动迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文