| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- using Abp.BackgroundJobs;
- using Abp.Notifications;
- using Microsoft.EntityFrameworkCore;
- using VberZero.BaseSystem;
- using VberZero.BaseSystem.MultiTenancy;
- using VberZero.BaseSystem.Users;
- using VberZero.Workflow;
- using VberZero.Workflow.DesignInfo;
- using VberZero.Workflow.Persistence;
- namespace VberZero.EntityFramework;
- /// <summary>
- /// Vber Zero的基础 DbContext。
- /// 从此类派生您的 DbContext 以拥有基本实体。
- /// </summary>
- public abstract class VzDbContext<TSelf> : VzCommonDbContext<TSelf>
- where TSelf : VzDbContext<TSelf>
- {
- /// <summary>
- /// Tenants
- /// </summary>
- public virtual DbSet<Tenant> Tenants { get; set; }
- public virtual DbSet<BackgroundJobInfo> BackgroundJobs { get; set; }
- public virtual DbSet<UserAccount> UserAccounts { get; set; }
- public virtual DbSet<NotificationInfo> Notifications { get; set; }
- #region WORKFLOW
- public DbSet<WorkflowEventInfo> WorkflowEvents { get; set; }
- public DbSet<WorkflowExecutionErrorInfo> WorkflowExecutionErrors { get; set; }
- public DbSet<WorkflowExecutionPointerInfo> WorkflowExecutionPointers { get; set; }
- public DbSet<WorkflowExtensionAttributeInfo> WorkflowExtensionAttributes { get; set; }
- public DbSet<WorkflowSubscriptionInfo> WorkflowSubscriptions { get; set; }
- public DbSet<WorkflowInfo> WorkflowWorkflows { get; set; }
- public DbSet<WorkflowDefinitionInfo> WorkflowWorkflowDefinitions { get; set; }
- public DbSet<CommonWorkflowAuditorInfo> CommonWorkflowAuditors { get; set; }
- #endregion WORKFLOW
- ///// <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; }
- /// <summary>
- ///
- /// </summary>
- /// <param name="options"></param>
- protected VzDbContext(DbContextOptions<TSelf> options)
- : base(options)
- {
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="modelBuilder"></param>
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
- base.OnModelCreating(modelBuilder);
- modelBuilder.ChangeTablePrefix();
- modelBuilder.Entity<BackgroundJobInfo>(b =>
- {
- b.HasIndex(e => new { e.IsAbandoned, e.NextTryTime });
- });
- 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<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 });
- });
- #region AuditLog.Set_MaxLengths
- modelBuilder.Entity<AuditLog>()
- .Property(e => e.ServiceName)
- .HasMaxLength(AuditLog.MaxServiceNameLength);
- modelBuilder.Entity<AuditLog>()
- .Property(e => e.MethodName)
- .HasMaxLength(AuditLog.MaxMethodNameLength);
- modelBuilder.Entity<AuditLog>()
- .Property(e => e.Parameters)
- .HasMaxLength(AuditLog.MaxParametersLength);
- modelBuilder.Entity<AuditLog>()
- .Property(e => e.ClientIpAddress)
- .HasMaxLength(AuditLog.MaxClientIpAddressLength);
- modelBuilder.Entity<AuditLog>()
- .Property(e => e.ClientName)
- .HasMaxLength(AuditLog.MaxClientNameLength);
- modelBuilder.Entity<AuditLog>()
- .Property(e => e.BrowserInfo)
- .HasMaxLength(AuditLog.MaxBrowserInfoLength);
- modelBuilder.Entity<AuditLog>()
- .Property(e => e.ExceptionMessage)
- .HasMaxLength(AuditLog.MaxExceptionMessageLength);
- modelBuilder.Entity<AuditLog>()
- .Property(e => e.Exception)
- .HasMaxLength(AuditLog.MaxExceptionLength);
- modelBuilder.Entity<AuditLog>()
- .Property(e => e.CustomData)
- .HasMaxLength(AuditLog.MaxCustomDataLength);
- #endregion AuditLog.Set_MaxLengths
- //modelBuilder.Entity<TenantFeatureSetting>(b =>
- //{
- // b.HasIndex(e => new { e.TenantId, e.Name });
- //});
- //modelBuilder.Entity<EditionFeatureSetting>(b =>
- //{
- // b.HasIndex(e => new { e.EditionId, e.Name });
- //});
- modelBuilder.ConfigWorkflow();
- }
- }
|