using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.Entity; using PalGain.Core; using PalGain.Core.Tasks; using sbcLabSystem.Data.Domain.Account; using sbcLabSystem.Data.Domain.Backstage; namespace sbcLabSystem.Data.DBContext { public class FreseniusDBContext : DbContext, IDbContext { //public IDbSet InterfaceInfos { get; set; } public IDbSet UserInfos { get; set; } public IDbSet RoleInfos { get; set; } public IDbSet ResourceInfos { get; set; } public IDbSet UserRequestInfos { get; set; } public IDbSet MenusInfo { get; set; } public IDbSet EmileInfo { get; set; } public IDbSet QCDistribution { get; set; } public IDbSet QCDistributionRegister { get; set; } public IDbSet ScheduleTaskes { get; set; } public IDbSet EmailSmtpInfos { get; set; } public IDbSet StandAnswerInfos { get; set; } public IDbSet ApprovalInfos { get; set; } public IDbSet Resultspercentage { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity() .HasMany(p => p.QCDistributionRegisters).WithRequired(p => p.QCDistributionInfo) .HasForeignKey(p => p.QCDistributionId).WillCascadeOnDelete(false); modelBuilder.Entity() .HasRequired(p => p.LabInfo).WithMany(p => p.QCDistributionRegisterInfos) .HasForeignKey(p => p.LabId).WillCascadeOnDelete(false); modelBuilder.Entity() .HasOptional(p => p.StandAnswer).WithRequired(p => p.QCDistInfo) .Map(p => p.MapKey("QCDistInfoId")) .WillCascadeOnDelete(true); base.OnModelCreating(modelBuilder); } public new IDbSet Set() where TEntity : BaseEntity { return base.Set(); } public IList ExecuteStoredProcedureList(string commandText, params object[] parameters) where TEntity : BaseEntity, new() { throw new NotImplementedException(); } public IEnumerable SqlQuery(string sql, params object[] parameters) { return this.Database.SqlQuery(sql, parameters); } public int ExecuteSqlCommand(string sql, bool doNotEnsureTransaction = false, int? timeout = null, params object[] parameters) { int? previousTimeout = null; //if (timeout.HasValue) //{ // //store previous timeout // previousTimeout = ((IObjectContextAdapter)this).ObjectContext.CommandTimeout; // ((IObjectContextAdapter)this).ObjectContext.CommandTimeout = timeout; //} var transactionalBehavior = doNotEnsureTransaction ? TransactionalBehavior.DoNotEnsureTransaction : TransactionalBehavior.EnsureTransaction; var result = this.Database.ExecuteSqlCommand(transactionalBehavior, sql, parameters); //if (timeout.HasValue) //{ // //Set previous timeout back // ((IObjectContextAdapter)this).ObjectContext.CommandTimeout = previousTimeout; //} //return result return result; } public void Detach(object entity) { throw new NotImplementedException(); } public bool ProxyCreationEnabled { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } } public bool AutoDetectChangesEnabled { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } } } }