我需要确保我的应用程序本身能够升级他的数据库模型(应用迁移)
在 ABP 架构中,我应该在哪里调用 Migrate?
context.Database.Migrate();
由于这是对基础架构逻辑(实体框架核心)的调用,因此应远离域服务和应用程序服务。
提前致谢
我需要确保我的应用程序本身能够升级他的数据库模型(应用迁移)
在 ABP 架构中,我应该在哪里调用 Migrate?
context.Database.Migrate();
由于这是对基础架构逻辑(实体框架核心)的调用,因此应远离域服务和应用程序服务。
提前致谢
我终于找到了一个可行的解决方案,适用于 abp 4.3 此代码允许您的应用程序在启动时应用迁移。
public override void PostInitialize()
{
var dbContextProvider = IocManager.Resolve<IDbContextProvider<ExtranetDbContext>>();
var unitOfWorkManager = IocManager.Resolve<IUnitOfWorkManager>();
using (var unitOfWork = unitOfWorkManager.Begin())
{
var context = dbContextProvider.GetDbContext(MultiTenancySides.Host);
//Removes actual connection as it has been enlisted in a non needed transaction for migration
context.Database.CloseConnection();
context.Database.Migrate();
}
if (!SkipDbSeed)
{
SeedHelper.SeedHostDb(IocManager);
}
}
IUnitOfWorkManager
可以在此处找到有关的详细信息。
您好,您可以在 EntityFrameworkCoreModule 的 PostInitialize 方法中执行数据库迁移。
public class MyApplicationEntityFrameworkCoreModule : AbpModule
{
public override void PostInitialize()
{
if (!SkipDbSeed)
{
SeedHelper.SeedHostDb(IocManager);
}
// --> You can execute migrations here <--
}
}