【发布时间】:2022-01-17 16:16:03
【问题描述】:
我在我的项目中使用代码优先数据库方法。我想反映对生产服务器的更改。 我尝试使用启动文件中的以下代码和平来实现此目标,但它不起作用:
using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
{
var context = serviceScope.ServiceProvider.GetRequiredService<BaseDBContext>();
var GetPendingMigrations = context.Database.GetPendingMigrations(); // Used to check data
var GetAppliedMigrarions = context.Database.GetAppliedMigrations();// Used to check data
context.Database.Migrate();
}
如何使用实体框架核心中的最新迁移文件更新生产数据库
【问题讨论】:
标签: c# entity-framework-core entity-framework-migrations