我已使用命令dotnet ef --startup-project ../Project.Web migrations add Init
因为我在不同的层(web层)中注册我的db上下文,并且有类库,所以我必须将我的启动项目设置为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; }
}
答案 0 :(得分:4)
只需移动它(并可选择更改类的命名空间)。新的迁移将跟随之前的迁移。 (同样的模型快照。)是的,它真棒。 ;)