c# - 如何将 EF 核心迁移添加到 .net 核心 2 类库?

标签 c# entity-framework entity-framework-core .net-core-2.0

我创建了一个 .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/

相关文章:

c# - C#中如何去除标签之间的文字?

c# - LINQ 动态 from 子句

c# - EntityFramework 测试初始化​​错误 : CREATE DATABASE statement not allowed within multi-statement transaction

c# - 具有多个值的 Entity Framework 核心 where 子句

c# - 从 Windows 窗体拖放到桌面和 Windows 资源管理器

c# - 使用 Entity Framework 映射到现有表

c# - "The owned entity type requires to be referenced from another entity type via a navigation"

c# - Entity Framework 相当于 SQL 相对更新

c# - .net core EF core 多对多插入

c# - 使用 Nuget.VisualStudio 安装 NuGet 包时如何生成绑定(bind)重定向?