我已经成功使用.NET Core类库创建了一个迁移文件,使用命令:
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”
Startup(在不同的项目中,业务层)
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; }
}