【问题标题】:.NET Core Entity Framework - Migration path --output-dir.NET Core Entity Framework - 迁移路径 --output-dir
【发布时间】:2017-07-03 08:34:49
【问题描述】:

我已经使用 .NET Core 类库通过使用命令成功创建了一个迁移文件:dotnet ef --startup-project ../Project.Web migrations add Init

因为我在不同的层(web 层)注册了我的数据库上下文,并且有类库,所以我必须将我的启动项目设置为 Project.Web。

创建初始迁移后,它看起来像这样:

但现在我想将迁移文件夹Project.Data/Migrations 移动到Project.Data/Database/Migrations

我尝试过使用 output-dir 参数:

dotnet ef --startup-project ../Project.Web --output-dir Database migrations add Init

然后我得到:

dotnet : 无法识别的选项 '--output-dir'

启动(在不同的项目、业务层)

public static IServiceCollection InjectBusinessContext(this IServiceCollection services, string connectionString)
{
    services.AddEntityFrameworkSqlServer().AddDbContext<ProjectContext>((serviceProvider, options) => options.UseSqlServer(connectionString, b => b.MigrationsAssembly("Database")).UseInternalServiceProvider(serviceProvider));

    return services;
}

上下文(数据层)

public class ProjectContext : DbContext
{
    public ProjectContext(DbContextOptions<ProjectContext> options) : base(options)
    {
    }

    public DbSet<Account> Account { get; set; }
}

【问题讨论】:

    标签: .net entity-framework asp.net-core .net-core entity-framework-core


    【解决方案1】:

    只需移动它(并可选择更改类的命名空间)。新的迁移将跟随之前的迁移。 (模型快照也是如此。)是的,这太棒了。 ;)

    【讨论】:

    • 那是……太棒了。干杯。
    猜你喜欢
    • 2017-10-27
    • 2021-06-11
    • 2018-11-05
    • 2020-03-09
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-07
    相关资源
    最近更新 更多