diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore/EntityFrameworkCore/MyProjectNameDbContext.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore/EntityFrameworkCore/MyProjectNameDbContext.cs index 43baa25f5a..9fdb0220e5 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore/EntityFrameworkCore/MyProjectNameDbContext.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore/EntityFrameworkCore/MyProjectNameDbContext.cs @@ -2,22 +2,56 @@ using Volo.Abp.AuditLogging.EntityFrameworkCore; using Volo.Abp.BackgroundJobs.EntityFrameworkCore; using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.FeatureManagement.EntityFrameworkCore; +using Volo.Abp.Identity; using Volo.Abp.Identity.EntityFrameworkCore; using Volo.Abp.IdentityServer.EntityFrameworkCore; using Volo.Abp.PermissionManagement.EntityFrameworkCore; using Volo.Abp.SettingManagement.EntityFrameworkCore; +using Volo.Abp.TenantManagement; using Volo.Abp.TenantManagement.EntityFrameworkCore; namespace MyCompanyName.MyProjectName.EntityFrameworkCore { + [ReplaceDbContext(typeof(IIdentityDbContext))] + [ReplaceDbContext(typeof(ITenantManagementDbContext))] [ConnectionStringName("Default")] - public class MyProjectNameDbContext : AbpDbContext + public class MyProjectNameDbContext : + AbpDbContext, + IIdentityDbContext, + ITenantManagementDbContext { - /* Add DbSet properties for your Aggregate Roots / Entities here. + /* Add DbSet properties for your Aggregate Roots / Entities here. */ + + #region Entities from the modules + + /* Notice: We only implemented IIdentityDbContext and ITenantManagementDbContext + * and replaced them for this DbContext. This allows you to perform JOIN + * queries for the entities of these modules over the repositories easily. You + * typically don't need that for other modules. But, if you need, you can + * implement the DbContext interface of the needed module and use ReplaceDbContext + * attribute just like IIdentityDbContext and ITenantManagementDbContext. + * + * More info: Replacing a DbContext of a module ensures that the related module + * uses this DbContext on runtime. Otherwise, it will use its own DbContext class. */ + + //Identity + public DbSet Users { get; set; } + public DbSet Roles { get; set; } + public DbSet ClaimTypes { get; set; } + public DbSet OrganizationUnits { get; set; } + public DbSet SecurityLogs { get; set; } + public DbSet LinkUsers { get; set; } + + // Tenant Management + public DbSet Tenants { get; set; } + public DbSet TenantConnectionStrings { get; set; } + #endregion + public MyProjectNameDbContext(DbContextOptions options) : base(options) {