[英]How to add EF core migrations to .net core 2 class library?
我创建了一个.net核心2类库。 我创建了实体和实体类型配置。 我创建了DbContext
public class EFDBContext : DbContext
{
public EFDBContext(DbContextOptions options) : base(options)
{
}
}
然后我创建了一个TemporaryDbContextFactory
public class TemporaryDbContextFactory : IDesignTimeDbContextFactory<EFDBContext>
{
public EFDBContext CreateDbContext(string[] args)
{
var builder = new DbContextOptionsBuilder<EFDBContext>();
builder.UseSqlServer("Name=AppConnectionString",
optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(EFDBContext).GetTypeInfo().Assembly.GetName().Name));
return new EFDBContext(builder.Options);
}
}
我正在尝试运行Add-Migration但我什么也没得到。 未创建迁移
那么我在这里失踪了什么?
听起来你正在遇到问题#10298 。 将以下内容添加到*.csproj
文件中:
<PropertyGroup>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.