这个问题在这里已有答案:
我使用Visual Studio向导创建了一个ASP.NET Core Web应用程序,该向导生成了所有DbContext内容。我目前正在尝试实施Enum Lookup Table Generator package。文件说:
在数据库初始化程序或EF迁移中从Seed方法运行
EnumToLookup.Apply()
。
我的问题是我的DbContext目前没有使用数据库初始化程序。
我应该在哪里运行EnumToLookup.Apply()
?我是否需要添加数据库初始化程序,以便我可以覆盖Seed()
方法,其中文档说放EnumToLookup.Apply()
?
我的DbContext看起来像这样:
namespace WebApplication3.Data
{
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
}
public DbSet<WebApplication3.Models.Restaurant> Restaurant { get; set; }
public DbSet<WebApplication3.Models.Customer> Customer { get; set; }
}
}
我做了一些更多的研究,结果发现虽然EF6能够添加种子数据,但EF7 / EF Core 2.0不包括这种能力。
This functionality may be added with the release of EF Core 2.1, but it might not make it in.