Ref*_*eft 3 .net entity-framework entity-framework-core .net-core asp.net-core
我已经使用 .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
Run Code Online (Sandbox Code Playgroud)
但后来我得到:
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;
}
Run Code Online (Sandbox Code Playgroud)
上下文(数据层)
public class ProjectContext : DbContext
{
public ProjectContext(DbContextOptions<ProjectContext> options) : base(options)
{
}
public DbSet<Account> Account { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3177 次 |
| 最近记录: |