我创建了一个 .net core 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>
关于c# - 如何将 EF 核心迁移添加到 .net 核心 2 类库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47574650/