| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- 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<TSelf> : VzCommonDbContext<TSelf>
- where TSelf : VzHostDbContext<TSelf>
- {
- /// <summary>
- /// Tenants
- /// </summary>
- public virtual DbSet<Tenant> Tenants { get; set; }
- ///// <summary>
- ///// Editions.
- ///// </summary>
- //public virtual DbSet<Edition> Editions { get; set; }
- ///// <summary>
- ///// FeatureSettings.
- ///// </summary>
- //public virtual DbSet<FeatureSetting> FeatureSettings { get; set; }
- ///// <summary>
- ///// TenantFeatureSetting.
- ///// </summary>
- //public virtual DbSet<TenantFeatureSetting> TenantFeatureSettings { get; set; }
- ///// <summary>
- ///// EditionFeatureSettings.
- ///// </summary>
- //public virtual DbSet<EditionFeatureSetting> EditionFeatureSettings { get; set; }
- public virtual DbSet<BackgroundJobInfo> BackgroundJobs { get; set; }
- public virtual DbSet<UserAccount> UserAccounts { get; set; }
- public virtual DbSet<NotificationInfo> Notifications { get; set; }
- /// <summary>
- ///
- /// </summary>
- /// <param name="options"></param>
- protected VzHostDbContext(DbContextOptions<TSelf> options)
- : base(options)
- {
- }
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
- base.OnModelCreating(modelBuilder);
- modelBuilder.Entity<Tenant>(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<BackgroundJobInfo>(b =>
- {
- b.HasIndex(e => new { e.IsAbandoned, e.NextTryTime });
- });
- modelBuilder.Entity<UserAccount>(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<TenantFeatureSetting>(b =>
- //{
- // b.HasIndex(e => new { e.TenantId, e.Name });
- //});
- //modelBuilder.Entity<EditionFeatureSetting>(b =>
- //{
- // b.HasIndex(e => new { e.EditionId, e.Name });
- //});
- }
- }
|