| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- using System.Data.Common;
- using System.Data.Entity;
- using System.Data.Entity.Core.Objects;
- using System.Data.Entity.Infrastructure;
- using System.Data.Entity.ModelConfiguration.Conventions;
- using Abp.Domain.Entities;
- using Abp.EntityFramework.Extensions;
- using Abp.Notifications;
- using IwbZero.Authorization.Base.SystemInfo;
- using IwbZero.Authorization.Base.Users;
- using IwbZero.Authorization.Roles;
- using IwbZero.Authorization.Users;
- using IwbZero.MultiTenancy;
- namespace IwbZero.EntityFramework
- {
- public abstract class IwbZeroDbContext<TTenant, TRole, TUser> : IwbZeroCommonDbContext<TRole, TUser>
- where TTenant : IwbTenant<TUser>
- where TRole : IwbSysRole<TUser>
- where TUser : IwbSysUser<TUser>
- {
- /// <summary>
- /// Tenants
- /// </summary>
- public virtual IDbSet<TTenant> Tenants { get; set; }
- ///// <summary>
- ///// Editions.
- ///// </summary>
- //public virtual IDbSet<Edition> Editions { get; set; }
- ///// <summary>
- ///// FeatureSettings.
- ///// </summary>
- //public virtual IDbSet<FeatureSetting> FeatureSettings { get; set; }
- ///// <summary>
- ///// TenantFeatureSetting.
- ///// </summary>
- //public virtual IDbSet<TenantFeatureSetting> TenantFeatureSettings { get; set; }
- ///// <summary>
- ///// EditionFeatureSettings.
- ///// </summary>
- //public virtual IDbSet<EditionFeatureSetting> EditionFeatureSettings { get; set; }
- ///// <summary>
- ///// Background jobs.
- ///// </summary>
- //public virtual IDbSet<BackgroundJobInfo> BackgroundJobs { get; set; }
- /// <summary>
- /// User accounts
- /// </summary>
- public virtual IDbSet<UserAccount> UserAccounts { get; set; }
- protected IwbZeroDbContext()
- {
- }
- protected IwbZeroDbContext(string nameOrConnectionString)
- : base(nameOrConnectionString)
- {
- }
- protected IwbZeroDbContext(DbCompiledModel model)
- : base(model)
- {
- }
- protected IwbZeroDbContext(DbConnection existingConnection, bool contextOwnsConnection)
- : base(existingConnection, contextOwnsConnection)
- {
- }
- protected IwbZeroDbContext(string nameOrConnectionString, DbCompiledModel model)
- : base(nameOrConnectionString, model)
- {
- }
- protected IwbZeroDbContext(ObjectContext objectContext, bool dbContextOwnsObjectContext)
- : base(objectContext, dbContextOwnsObjectContext)
- {
- }
- protected IwbZeroDbContext(DbConnection existingConnection, DbCompiledModel model, bool contextOwnsConnection)
- : base(existingConnection, model, contextOwnsConnection)
- {
- }
- protected override void OnModelCreating(DbModelBuilder modelBuilder)
- {
- base.OnModelCreating(modelBuilder);
- //#region BackgroundJobInfo.IX_IsAbandoned_NextTryTime
- //modelBuilder.Entity<BackgroundJobInfo>()
- // .Property(j => j.IsAbandoned)
- // .CreateIndex("IX_IsAbandoned_NextTryTime", 1);
- //modelBuilder.Entity<BackgroundJobInfo>()
- // .Property(j => j.NextTryTime)
- // .CreateIndex("IX_IsAbandoned_NextTryTime", 2);
- //#endregion
- #region NotificationSubscriptionInfo.IX_NotificationName_EntityTypeName_EntityId_UserId
- modelBuilder.Entity<NotificationSubscriptionInfo>()
- .Property(ns => ns.NotificationName)
- .CreateIndex("IX_NotificationName_EntityTypeName_EntityId_UserId", 1);
- modelBuilder.Entity<NotificationSubscriptionInfo>()
- .Property(ns => ns.EntityTypeName)
- .CreateIndex("IX_NotificationName_EntityTypeName_EntityId_UserId", 2);
- modelBuilder.Entity<NotificationSubscriptionInfo>()
- .Property(ns => ns.EntityId)
- .CreateIndex("IX_NotificationName_EntityTypeName_EntityId_UserId", 3);
- modelBuilder.Entity<NotificationSubscriptionInfo>()
- .Property(ns => ns.UserId)
- .CreateIndex("IX_NotificationName_EntityTypeName_EntityId_UserId", 4);
- #endregion
- #region UserNotificationInfo.IX_UserId_State_CreationTime
- modelBuilder.Entity<UserNotificationInfo>()
- .Property(un => un.UserId)
- .CreateIndex("IX_UserId_State_CreationTime", 1);
- modelBuilder.Entity<UserNotificationInfo>()
- .Property(un => un.State)
- .CreateIndex("IX_UserId_State_CreationTime", 2);
- modelBuilder.Entity<UserNotificationInfo>()
- .Property(un => un.CreationTime)
- .CreateIndex("IX_UserId_State_CreationTime", 3);
- #endregion
- #region UserLoginAttempt.IX_TenancyName_UserNameOrEmailAddress_Result
- modelBuilder.Entity<UserLoginAttempt>()
- .Property(ula => ula.TenancyName)
- .CreateIndex("IX_TenancyName_UserNameOrEmailAddress_Result", 1);
- modelBuilder.Entity<UserLoginAttempt>()
- .Property(ula => ula.UserNameOrEmailAddress)
- .CreateIndex("IX_TenancyName_UserNameOrEmailAddress_Result", 2);
- modelBuilder.Entity<UserLoginAttempt>()
- .Property(ula => ula.Result)
- .CreateIndex("IX_TenancyName_UserNameOrEmailAddress_Result", 3);
- #endregion
- #region UserLoginAttempt.IX_UserId_TenantId
- modelBuilder.Entity<UserLoginAttempt>()
- .Property(ula => ula.UserId)
- .CreateIndex("IX_UserId_TenantId", 1);
- modelBuilder.Entity<UserLoginAttempt>()
- .Property(ula => ula.TenantId)
- .CreateIndex("IX_UserId_TenantId", 2);
- #endregion
- #region SysLog.Set_MaxLengths
- modelBuilder.Entity<SysLog>()
- .Property(e => e.ServiceName)
- .HasMaxLength(SysLog.MaxServiceNameLength);
- modelBuilder.Entity<SysLog>()
- .Property(e => e.MethodName)
- .HasMaxLength(SysLog.MaxMethodNameLength);
- modelBuilder.Entity<SysLog>()
- .Property(e => e.Parameters)
- .HasMaxLength(SysLog.MaxParametersLength);
- modelBuilder.Entity<SysLog>()
- .Property(e => e.ClientIpAddress)
- .HasMaxLength(SysLog.MaxClientIpAddressLength);
- modelBuilder.Entity<SysLog>()
- .Property(e => e.ClientName)
- .HasMaxLength(SysLog.MaxClientNameLength);
- modelBuilder.Entity<SysLog>()
- .Property(e => e.BrowserInfo)
- .HasMaxLength(SysLog.MaxBrowserInfoLength);
- modelBuilder.Entity<SysLog>()
- .Property(e => e.Exception)
- .HasMaxLength(SysLog.MaxExceptionLength);
- modelBuilder.Entity<SysLog>()
- .Property(e => e.CustomData)
- .HasMaxLength(SysLog.MaxCustomDataLength);
- #endregion
- #region Common Indexes
- modelBuilder.Conventions.AddAfter<IndexAttributeConvention>(new IndexingPropertyConvention<ISoftDelete, bool>(m => m.IsDeleted));
- modelBuilder.Conventions.AddAfter<IndexAttributeConvention>(new IndexingPropertyConvention<IMayHaveTenant, int?>(m => m.TenantId));
- modelBuilder.Conventions.AddAfter<IndexAttributeConvention>(new IndexingPropertyConvention<IMustHaveTenant, int>(m => m.TenantId));
- #endregion
- }
- }
- }
|