using Abp.BackgroundJobs; using Abp.Notifications; using Microsoft.EntityFrameworkCore; using VberZero.BaseSystem.MultiTenancy; using VberZero.BaseSystem.Users; namespace VberZero.EntityFramework; [Abp.MultiTenancy.MultiTenancySide(Abp.MultiTenancy.MultiTenancySides.Host)] public abstract class VzHostDbContext : VzCommonDbContext where TSelf : VzHostDbContext { /// /// Tenants /// public virtual DbSet Tenants { get; set; } ///// ///// Editions. ///// //public virtual DbSet Editions { get; set; } ///// ///// FeatureSettings. ///// //public virtual DbSet FeatureSettings { get; set; } ///// ///// TenantFeatureSetting. ///// //public virtual DbSet TenantFeatureSettings { get; set; } ///// ///// EditionFeatureSettings. ///// //public virtual DbSet EditionFeatureSettings { get; set; } public virtual DbSet BackgroundJobs { get; set; } public virtual DbSet UserAccounts { get; set; } public virtual DbSet Notifications { get; set; } /// /// /// /// protected VzHostDbContext(DbContextOptions options) : base(options) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity(b => { b.HasOne(p => p.DeleterUser) .WithMany() .HasForeignKey(p => p.DeleterUserId); b.HasOne(p => p.CreatorUser) .WithMany() .HasForeignKey(p => p.CreatorUserId); b.HasOne(p => p.LastModifierUser) .WithMany() .HasForeignKey(p => p.LastModifierUserId); b.HasIndex(e => e.TenancyName); }); modelBuilder.Entity(b => { b.HasIndex(e => new { e.IsAbandoned, e.NextTryTime }); }); modelBuilder.Entity(b => { b.HasIndex(e => new { e.TenantId, e.UserId }); b.HasIndex(e => new { e.TenantId, e.UserName }); b.HasIndex(e => new { e.TenantId, e.EmailAddress }); b.HasIndex(e => new { e.UserName }); b.HasIndex(e => new { e.EmailAddress }); }); //modelBuilder.Entity(b => //{ // b.HasIndex(e => new { e.TenantId, e.Name }); //}); //modelBuilder.Entity(b => //{ // b.HasIndex(e => new { e.EditionId, e.Name }); //}); } }