.NET核心实体框架 - 迁移路径--output-dir

时间:2017-02-14 21:28:35

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

我已使用命令dotnet ef --startup-project ../Project.Web migrations add Init

成功使用.NET Core类库创建了一个迁移文件

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

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

enter image description here

但现在我想将迁移文件夹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; }
}

1 个答案:

答案 0 :(得分:4)

只需移动它(并可选择更改类的命名空间)。新的迁移将跟随之前的迁移。 (同样的模型快照。)是的,它真棒。 ;)