using System.Data.Common; using System.Data.Entity; using System.Data.Entity.Core.Objects; using System.Data.Entity.Infrastructure; using Abp.EntityFramework; using IwbZero.Authorization.Permissions; using IwbZero.Authorization.Roles; using IwbZero.Authorization.Users; using IwbZero.BaseSysInfo; namespace IwbZero { public abstract class IwbDbContext : AbpDbContext where TRole : IwbSysRole,new() where TUser : IwbSysUser,new() //where TFun: IwbSysFunction,new() { //TODO: Define an IDbSet for each Entity... public virtual IDbSet Users { get; set; } public virtual IDbSet UserLogins { get; set; } public virtual IDbSet UserLoginLogs { get; set; } public virtual IDbSet Roles { get; set; } public virtual IDbSet UserRoles { get; set; } public virtual IDbSet Permissions { get; set; } //public virtual IDbSet Functions { get; set; } //public virtual IDbSet> Settings { get; set; } //public virtual IDbSet> SysStates { get; set; } //Example: //public virtual IDbSet Users { get; set; } /* NOTE: * Setting "Default" to base class helps us when working migration commands on Package Manager Console. * But it may cause problems when working Migrate.exe of EF. If you will apply migrations on command line, do not * pass connection string name to base classes. ABP works either way. */ /// /// Default constructor. /// Do not directly instantiate this class. Instead, use dependency injection! /// protected IwbDbContext() { } /// /// Constructor with connection string parameter. /// /// Connection string or a name in connection strings in configuration file protected IwbDbContext(string nameOrConnectionString) : base(nameOrConnectionString) { } protected IwbDbContext(DbCompiledModel model) : base(model) { } /// /// This constructor can be used for unit tests. /// protected IwbDbContext(DbConnection existingConnection, bool contextOwnsConnection) : base(existingConnection, contextOwnsConnection) { } protected IwbDbContext(string nameOrConnectionString, DbCompiledModel model) : base(nameOrConnectionString, model) { } protected IwbDbContext(ObjectContext objectContext, bool dbContextOwnsObjectContext) : base(objectContext, dbContextOwnsObjectContext) { } /// /// Constructor. /// protected IwbDbContext(DbConnection existingConnection, DbCompiledModel model, bool contextOwnsConnection) : base(existingConnection, model, contextOwnsConnection) { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); #region IwbSysLog.Set_MaxLengths modelBuilder.Entity() .Property(e => e.ServiceName) .HasMaxLength(IwbSysLog.MaxServiceNameLength); modelBuilder.Entity() .Property(e => e.MethodName) .HasMaxLength(IwbSysLog.MaxMethodNameLength); modelBuilder.Entity() .Property(e => e.Parameters) .HasMaxLength(IwbSysLog.MaxParametersLength); modelBuilder.Entity() .Property(e => e.ClientIpAddress) .HasMaxLength(IwbSysLog.MaxClientIpAddressLength); modelBuilder.Entity() .Property(e => e.ClientName) .HasMaxLength(IwbSysLog.MaxClientNameLength); modelBuilder.Entity() .Property(e => e.BrowserInfo) .HasMaxLength(IwbSysLog.MaxBrowserInfoLength); modelBuilder.Entity() .Property(e => e.Exception) .HasMaxLength(IwbSysLog.MaxExceptionLength); modelBuilder.Entity() .Property(e => e.CustomData) .HasMaxLength(IwbSysLog.MaxCustomDataLength); #endregion } } }