| | |
| | | using System.Linq; |
| | | using System; |
| | | using System.Linq; |
| | | using RiskControl.NewService.Entity; |
| | | using SqlSugar; |
| | | using System.Configuration; |
| | | using System.Diagnostics; |
| | | |
| | | namespace RiskControl.NewService.Service |
| | | { |
| | | public class DbContext |
| | | { |
| | | public DbContext() |
| | | { |
| | | |
| | | RiskControlRRDb = new SqlSugarClient(new ConnectionConfig() |
| | | { |
| | | ConnectionString = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString, |
| | | DbType = DbType.SqlServer, |
| | | IsAutoCloseConnection = true, |
| | | ConfigureExternalServices = new ConfigureExternalServices() |
| | | { |
| | | |
| | | } |
| | | }); |
| | | |
| | | CreditRatingDb = new SqlSugarClient(new ConnectionConfig() |
| | | { |
| | | ConnectionString = ConfigurationManager.ConnectionStrings["connStrCreditRating"].ConnectionString, |
| | | DbType = DbType.SqlServer, |
| | | IsAutoCloseConnection = true, |
| | | ConfigureExternalServices = new ConfigureExternalServices() |
| | | { |
| | | |
| | | } |
| | | }); |
| | | NeeqDb = new SqlSugarClient(new ConnectionConfig() |
| | | { |
| | | ConnectionString = ConfigurationManager.ConnectionStrings["connStrNeeq"].ConnectionString, |
| | | DbType = DbType.SqlServer, |
| | | IsAutoCloseConnection = true, |
| | | ConfigureExternalServices = new ConfigureExternalServices() |
| | | { |
| | | |
| | | } |
| | | }); |
| | | CityDb = new SqlSugarClient(new ConnectionConfig() |
| | | { |
| | | ConnectionString = ConfigurationManager.ConnectionStrings["connStrCity"].ConnectionString, |
| | | DbType = DbType.SqlServer, |
| | | IsAutoCloseConnection = true, |
| | | ConfigureExternalServices = new ConfigureExternalServices() |
| | | { |
| | | |
| | | } |
| | | }); |
| | | StockDlDb = new SqlSugarClient(new ConnectionConfig() |
| | | { |
| | | ConnectionString = ConfigurationManager.ConnectionStrings["connStrXt"].ConnectionString, |
| | | DbType = DbType.SqlServer, |
| | | IsAutoCloseConnection = true, |
| | | ConfigureExternalServices = new ConfigureExternalServices() |
| | | { |
| | | |
| | | } |
| | | }); |
| | | zdDb = new SqlSugarClient(new ConnectionConfig() |
| | | { |
| | | ConnectionString = ConfigurationManager.ConnectionStrings["connStrZd"].ConnectionString, |
| | | DbType = DbType.SqlServer, |
| | | IsAutoCloseConnection = true, |
| | | ConfigureExternalServices = new ConfigureExternalServices() |
| | | { |
| | | |
| | | } |
| | | }); |
| | | alarmDb = new SqlSugarClient(new ConnectionConfig() |
| | | { |
| | | ConnectionString = ConfigurationManager.ConnectionStrings["connStrAlarm"].ConnectionString, |
| | | DbType = DbType.SqlServer, |
| | | IsAutoCloseConnection = true, |
| | | ConfigureExternalServices = new ConfigureExternalServices() |
| | | { |
| | | |
| | | } |
| | | }); |
| | | RRAutoBIDB = new SqlSugarClient(new ConnectionConfig() |
| | | { |
| | | ConnectionString = ConfigurationManager.ConnectionStrings["connStrRRAutoBIDB"].ConnectionString, |
| | | DbType = DbType.SqlServer, |
| | | IsAutoCloseConnection = true, |
| | | ConfigureExternalServices = new ConfigureExternalServices() |
| | | { |
| | | |
| | | } |
| | | }); |
| | | RRIndustryDb = new SqlSugarClient(new ConnectionConfig() |
| | | { |
| | | ConnectionString = ConfigurationManager.ConnectionStrings["connIndustry"].ConnectionString, |
| | | DbType = DbType.SqlServer, |
| | | IsAutoCloseConnection = true, |
| | | ConfigureExternalServices = new ConfigureExternalServices() |
| | | { |
| | | |
| | | } |
| | | }); |
| | | RiskControlStockDL = new SqlSugarClient(new ConnectionConfig() |
| | | { |
| | | ConnectionString = ConfigurationManager.ConnectionStrings["connStrXt"].ConnectionString, |
| | | DbType = DbType.SqlServer, |
| | | IsAutoCloseConnection = true, |
| | | ConfigureExternalServices = new ConfigureExternalServices() |
| | | { |
| | | |
| | | } |
| | | }); |
| | | //调式代码 用来打印SQL |
| | | RiskControlRRDb.Aop.OnLogExecuting = (sql, pars) => |
| | | { |
| | | string s = sql; |
| | | System.Diagnostics.Debug.WriteLine(sql + "\r\n" + |
| | | RiskControlRRDb.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value))); |
| | | |
| | | }; |
| | | //调式代码 用来打印SQL |
| | | CreditRatingDb.Aop.OnLogExecuting = (sql, pars) => |
| | | { |
| | | string s = sql; |
| | | System.Diagnostics.Debug.WriteLine(sql + "\r\n" + |
| | | CreditRatingDb.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value))); |
| | | |
| | | }; |
| | | //调式代码 用来打印SQL |
| | | NeeqDb.Aop.OnLogExecuting = (sql, pars) => |
| | | { |
| | | string s = sql; |
| | | System.Diagnostics.Debug.WriteLine(sql + "\r\n" + |
| | | NeeqDb.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value))); |
| | | |
| | | }; |
| | | CityDb.Aop.OnLogExecuting = (sql, pars) => |
| | | { |
| | | string s = sql; |
| | | System.Diagnostics.Debug.WriteLine(sql + "\r\n" + |
| | | CityDb.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value))); |
| | | |
| | | }; |
| | | zdDb.Aop.OnLogExecuting = (sql, pars) => |
| | | { |
| | | string s = sql; |
| | | System.Diagnostics.Debug.WriteLine(sql + "\r\n" + |
| | | zdDb.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value))); |
| | | |
| | | }; |
| | | alarmDb.Aop.OnLogExecuting = (sql, pars) => |
| | | { |
| | | string s = sql; |
| | | System.Diagnostics.Debug.WriteLine(sql + "\r\n" + |
| | | alarmDb.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value))); |
| | | |
| | | }; |
| | | RRAutoBIDB.Aop.OnLogExecuting = (sql, pars) => |
| | | { |
| | | string s = sql; |
| | | System.Diagnostics.Debug.WriteLine(sql + "\r\n" + |
| | | RRAutoBIDB.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value))); |
| | | |
| | | }; |
| | | RRIndustryDb.Aop.OnLogExecuting = (sql, pars) => |
| | | { |
| | | string s = sql; |
| | | System.Diagnostics.Debug.WriteLine(sql + "\r\n" + |
| | | RRIndustryDb.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value))); |
| | | |
| | | }; |
| | | RiskControlStockDL.Aop.OnLogExecuting = (sql, pars) => |
| | | { |
| | | string s = sql; |
| | | System.Diagnostics.Debug.WriteLine(sql + "\r\n" + |
| | | RiskControlStockDL.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value))); |
| | | |
| | | }; |
| | | } |
| | | public static SqlSugarClient RiskControlRRDb;//用来处理事务多表查询和复杂的操作 |
| | | public static SqlSugarClient CreditRatingDb; |
| | | public static SqlSugarClient NeeqDb; |
| | | public static SqlSugarClient CityDb; |
| | | public static SqlSugarClient StockDlDb; |
| | | public static SqlSugarClient zdDb; |
| | | public static SqlSugarClient alarmDb; |
| | | public static SqlSugarClient RRAutoBIDB; |
| | | public static SqlSugarClient RRIndustryDb; |
| | | public static SqlSugarClient RiskControlStockDL; |
| | | public static SqlSugarScope RiskControlRRDb = GetSqlSugarScope("connStr");//用来处理事务多表查询和复杂的操作 |
| | | public static SqlSugarScope CreditRatingDb = GetSqlSugarScope("connStrCreditRating"); |
| | | public static SqlSugarScope NeeqDb = GetSqlSugarScope("connStrNeeq"); |
| | | public static SqlSugarScope CityDb = GetSqlSugarScope("connStrCity"); |
| | | public static SqlSugarScope StockDlDb = GetSqlSugarScope("connStrXt"); |
| | | public static SqlSugarScope zdDb = GetSqlSugarScope("connStrZd"); |
| | | public static SqlSugarScope alarmDb = GetSqlSugarScope("connStrAlarm"); |
| | | public static SqlSugarScope RRAutoBIDB = GetSqlSugarScope("connStrRRAutoBIDB"); |
| | | public static SqlSugarScope RRIndustryDb = GetSqlSugarScope("connIndustry"); |
| | | public static SqlSugarScope RiskControlStockDL = GetSqlSugarScope("connStrXt"); |
| | | |
| | | public SimpleClient<T> GetClient<T>() where T : BaseEntity, new() |
| | | { |
| | | return new SimpleClient<T>(RiskControlRRDb); |
| | | } |
| | | |
| | | static SqlSugarScope GetSqlSugarScope(string key) |
| | | { |
| | | var res = new SqlSugarScope(new ConnectionConfig() |
| | | { |
| | | ConnectionString = ConfigurationManager.ConnectionStrings[key].ConnectionString, |
| | | DbType = DbType.SqlServer, |
| | | IsAutoCloseConnection = true, |
| | | ConfigureExternalServices = new ConfigureExternalServices() |
| | | { |
| | | |
| | | } |
| | | }, db => |
| | | db.Aop.OnLogExecuting = (sql, pars) => |
| | | { |
| | | var s= UtilMethods.GetSqlString(DbType.SqlServer, sql, pars); |
| | | #if DEBUG |
| | | Debug.WriteLine(s); |
| | | #endif |
| | | }); |
| | | return res; |
| | | } |
| | | } |
| | | } |