2

我已经成功地通过使用命令创建使用.NET核心类库迁移文件迁移路径:dotnet ef --startup-project ../Project.Web migrations add Init.NET核心实体框架 - --output-dir的

因为我注册在不同的层我的分贝范围内,( Web层),并有类库,我必须将我的启动项目设置为Project.Web。

创建我最初的迁移之后,它看起来是这样的:

enter image description here

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

我一直在使用输出目录参数尝试:

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

但后来我得到:

DOTNET:无法识别的选项 ' - 输出-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; } 
} 

回答

2

just m它(并且可选地改变类的命名空间)。新的迁移将与之前的迁移相适应。 (模型快照同上)是的,这真棒。 ;)

+0

这是..真棒。干杯。 – Reft