songjun
2025-09-15 15e82c0dd4200a332b30e2fcd458ad84e2e3d428
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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<InterfaceInfo> InterfaceInfos { get; set; } 
        public IDbSet<UserInfo> UserInfos { get; set; }
        public IDbSet<RoleInfo> RoleInfos { get; set; }
        public IDbSet<ResourceInfo> ResourceInfos { get; set; } 
        public IDbSet<UserRequestInfo> UserRequestInfos { get; set; }
        public IDbSet<Menus> MenusInfo { get; set; }
        public IDbSet<EmileInfo> EmileInfo { get; set; } 
        public IDbSet<QCDistribution> QCDistribution { get; set; }
        public IDbSet<QCDistributionRegisterInfo> QCDistributionRegister { get; set; } 
        public IDbSet<ScheduleTask> ScheduleTaskes { get; set; }
        public IDbSet<EmailSmtpInfo> EmailSmtpInfos { get; set; }
        public IDbSet<StandAnswerInfo> StandAnswerInfos { get; set; }
        public IDbSet<ApprovalInfo> ApprovalInfos { get; set; }
        public IDbSet<Resultspercentage> Resultspercentage { get; set; }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<QCDistribution>()
                .HasMany(p => p.QCDistributionRegisters).WithRequired(p => p.QCDistributionInfo)
                .HasForeignKey(p => p.QCDistributionId).WillCascadeOnDelete(false);
            modelBuilder.Entity<QCDistributionRegisterInfo>()
                .HasRequired(p => p.LabInfo).WithMany(p => p.QCDistributionRegisterInfos)
                .HasForeignKey(p => p.LabId).WillCascadeOnDelete(false);
            modelBuilder.Entity<QCDistribution>() 
                .HasOptional(p => p.StandAnswer).WithRequired(p => p.QCDistInfo)
                .Map(p => p.MapKey("QCDistInfoId"))
                .WillCascadeOnDelete(true); 
            base.OnModelCreating(modelBuilder);
        }
 
        public new IDbSet<TEntity> Set<TEntity>() where TEntity : BaseEntity
        {
            return base.Set<TEntity>();
        }
 
        public IList<TEntity> ExecuteStoredProcedureList<TEntity>(string commandText, params object[] parameters) where TEntity : BaseEntity, new()
        {
            throw new NotImplementedException();
        }
 
        public IEnumerable<TElement> SqlQuery<TElement>(string sql, params object[] parameters)
        {
            return this.Database.SqlQuery<TElement>(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();
            }
        }
    }
}