【发布时间】: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