【发布时间】:2021-06-14 20:40:31
【问题描述】:
我在我的项目中使用 EF 核心,我想使用编程(不是命令)迁移我的上下文 所以我一一使用这两个概念
1.
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
var context = serviceScope.ServiceProvider.GetService<UserInformationContext>();
context.Database.Migrate();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserInformationContext userContext)
{
userContext.Database.Migrate();
}
问题是,使用这两个概念不能像add-migration 命令那样创建任何迁移文件夹
有没有办法使用编程创建迁移文件夹和迁移上下文??
【问题讨论】:
-
您能告诉我为什么需要迁移文件夹和迁移上下文吗?看来这两件事只能通过命令行来创建。
标签: c# asp.net-core entity-framework-core migration database-migration