英文:
How to make ABP find db context created by myself?
问题
I have used approach of several db contexts in ABP. I seperated ABP Identity module from other ABP modules. First of all I created new context for ABP Identity module using this articles - https://docs.abp.io/en/abp/latest/Entity-Framework-Core-Migrations#create-a-second-dbcontext and https://docs.abp.io/en/abp/latest/Entity-Framework-Core-Migrations#separating-host-tenant-database-schemas. As a result I have two db contexts.
First one:
[ReplaceDbContext(typeof(ITenantManagementDbContext))]
[ConnectionStringName("Default")]
public class OMSBlazorDbContext :
AbpDbContext<OMSBlazorDbContext>,
ITenantManagementDbContext
{
/* Add DbSet properties for your Aggregate Roots / Entities here. */
public DbSet<CustomerDemographics> CustomerDemographics { get; set; }
// Tenant Management
public DbSet<Tenant> Tenants { get; set; }
public DbSet<TenantConnectionString> TenantConnectionStrings { get; set; }
public OMSBlazorDbContext(DbContextOptions<OMSBlazorDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<CustomerDemographics>(b =>
{
b.ToTable("CustomerDemographics");
b.HasKey(x => x.CustomerTypeId);
b.HasData(new CustomerDemographics() { CustomerTypeId = 1, CustomerDescription = "Lorem ipsum" });
});
builder.ConfigurePermissionManagement();
builder.ConfigureSettingManagement();
builder.ConfigureBackgroundJobs();
builder.ConfigureOpenIddict();
builder.ConfigureTenantManagement();
}
}
Second one that contains identity:
[ReplaceDbContext(typeof(IIdentityDbContext))]
[ConnectionStringName("AbpIdentity")]
public class OMSBlazorIdentityDbContext :
AbpDbContext<OMSBlazorIdentityDbContext>,
IIdentityDbContext
{
public OMSBlazorIdentityDbContext(DbContextOptions<OMSBlazorIdentityDbContext> options) : base(options)
{
}
public DbSet<IdentityUser> Users { get; set; }
public DbSet<IdentityRole> Roles { get; set; }
public DbSet<IdentityClaimType> ClaimTypes { get; set; }
public DbSet<OrganizationUnit> OrganizationUnits { get; set; }
public DbSet<IdentitySecurityLog> SecurityLogs { get; set; }
public DbSet<IdentityLinkUser> LinkUsers { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
builder.SetMultiTenancySide(MultiTenancySides.Host);
base.OnModelCreating(builder);
builder.ConfigureIdentity();
builder.ConfigureFeatureManagement();
builder.ConfigureAuditLogging();
}
}
When I start my Blazor app it shows me error that AbpFeatureGroups
table not found but this table is situated in the second database (that one which can be accessed using OMSBlazorIdentityDbContext
).
Why ABP cannot find AbpFeatureGroups
table? Looks like ABP try to find this table in the first db context whileas it is in the second one that's my idea but in that case how to make it use second context. Correct me if I am wrong, please.
英文:
I have used approach of several db contexts in ABP. I seperated ABP Identity module from other ABP modules. First of all I created new context for ABP Identity module using this articles - https://docs.abp.io/en/abp/latest/Entity-Framework-Core-Migrations#create-a-second-dbcontext and https://docs.abp.io/en/abp/latest/Entity-Framework-Core-Migrations#separating-host-tenant-database-schemas. As a result I have two db contexts.
First one:
[ReplaceDbContext(typeof(ITenantManagementDbContext))]
[ConnectionStringName("Default")]
public class OMSBlazorDbContext :
AbpDbContext<OMSBlazorDbContext>,
ITenantManagementDbContext
{
/* Add DbSet properties for your Aggregate Roots / Entities here. */
public DbSet<CustomerDemographics> CustomerDemographics { get; set; }
// Tenant Management
public DbSet<Tenant> Tenants { get; set; }
public DbSet<TenantConnectionString> TenantConnectionStrings { get; set; }
public OMSBlazorDbContext(DbContextOptions<OMSBlazorDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<CustomerDemographics>(b =>
{
b.ToTable("CustomerDemographics");
b.HasKey(x => x.CustomerTypeId);
b.HasData(new CustomerDemographics() { CustomerTypeId = 1, CustomerDescription = "Lorem ipsum" });
});
builder.ConfigurePermissionManagement();
builder.ConfigureSettingManagement();
builder.ConfigureBackgroundJobs();
builder.ConfigureOpenIddict();
builder.ConfigureTenantManagement();
}
}
Second one that contains identity:
[ReplaceDbContext(typeof(IIdentityDbContext))]
[ConnectionStringName("AbpIdentity")]
public class OMSBlazorIdentityDbContext :
AbpDbContext<OMSBlazorIdentityDbContext>,
IIdentityDbContext
{
public OMSBlazorIdentityDbContext(DbContextOptions<OMSBlazorIdentityDbContext> options) : base(options)
{
}
public DbSet<IdentityUser> Users { get; set; }
public DbSet<IdentityRole> Roles { get; set; }
public DbSet<IdentityClaimType> ClaimTypes { get; set; }
public DbSet<OrganizationUnit> OrganizationUnits { get; set; }
public DbSet<IdentitySecurityLog> SecurityLogs { get; set; }
public DbSet<IdentityLinkUser> LinkUsers { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
builder.SetMultiTenancySide(MultiTenancySides.Host);
base.OnModelCreating(builder);
builder.ConfigureIdentity();
builder.ConfigureFeatureManagement();
builder.ConfigureAuditLogging();
}
}
When I start my Blazor app it shows me error that AbpFeatureGroups
table not found but this table is situated in the second database (that one which can be accessed using OMSBlazorIdentityDbContext
).
Why ABP cannot find AbpFeatureGroups
table? Looks like ABP try to find this table in the first db context whileas it is in the second one that's my idea but in that case how to make it use second context. Correct me if I am wrong, please.
答案1
得分: 0
添加到 appsettings.json
的 ConnectionString
部分的解决方案是添加名为 "AbpFeatureManagement" 的连接字符串,并将其设置为指向包含 AbpFeatureGroups
表的数据库的连接字符串。希望对您有所帮助。
英文:
The soultion that worked was adding to the appsettings.json
's ConnectionString
section connection string with name "AbpFeatureManagement" and setting it to the connection string which lead to database where AbpFeatureGroups
table is. Hope it helps
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论