diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Config.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Config.cs index 540bf35ba..7d87d0ee6 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Config.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Config.cs @@ -9,5 +9,7 @@ namespace OrmTest public class Config { public static string ConnectionString = "server=.;uid=sa;pwd=sasa;database=SqlSugar4XTest"; + public static string ConnectionString2 = "server=.;uid=sa;pwd=sasa;database=SQLSUGAR4XTEST"; + public static string ConnectionString3 = "server=.;uid=sa;pwd=sasa;database=sqlsugar4xtest"; } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Demos/A_MasterSlave.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Demos/A_MasterSlave.cs new file mode 100644 index 000000000..112d6a776 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Demos/A_MasterSlave.cs @@ -0,0 +1,44 @@ +using OrmTest.Demo; +using OrmTest.Models; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OrmTest.Demo +{ + public class MasterSlave : DemoBase + { + + public static void Init() + { + + for (int i = 0; i < 1000; i++) + { + var db = GetMasterSlaveInstance(); + var list = db.Insertable(new Student() { Name="aa" }).ExecuteCommand(); // ConnectionString2 or ConnectionString3 + } + //db.Insertable(new Student() { Name = "masterTest" }).ExecuteCommand();// Config.ConnectionString + } + + public static SqlSugarClient GetMasterSlaveInstance() + { + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() + { + ConnectionString = Config.ConnectionString, + DbType = DbType.SqlServer, + IsAutoCloseConnection = true, + SlaveConnectionConfigs = new List() { + new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 } , + new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 } + } + }); + db.Aop.OnLogExecuting = (sql, pars) => + { + Console.WriteLine(db.Ado.Connection.ConnectionString); + }; + return db; + } + } +} diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Demos/B_SharedConnection.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Demos/B_SharedConnection.cs new file mode 100644 index 000000000..d774d05f2 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Demos/B_SharedConnection.cs @@ -0,0 +1,87 @@ +using OrmTest.Models; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OrmTest.Demo +{ + public class SharedConnection : DemoBase + { + public static void Init() + { + StudentDal studentDal = new StudentDal(); + SchoolDal schoolDal = new SchoolDal(); + + try + { + studentDal.BeginTran(); + + Console.WriteLine("school Count:"+ schoolDal.GetSchoolCount());//0 + + studentDal.AddStudent(new Student() { Name = "StudentTest" }); + schoolDal.AddSchool(new School() { Name = "SchoolTest" });//1 + + Console.WriteLine("school Count:" + schoolDal.GetSchoolCount()); + + throw new Exception("error"); + } + catch (Exception ex) + { + studentDal.RollbackTran(); + Console.WriteLine("school Count:" + schoolDal.GetSchoolCount());//0 + } + } + + + } + public class StudentDal : BaseDao + { + public void AddStudent(Student sudent) + { + db.Insertable(sudent).ExecuteCommand(); + } + } + public class SchoolDal : BaseDao + { + public void AddSchool(School school) + { + db.Insertable(school).ExecuteCommand(); + } + public int GetSchoolCount() + { + return db.Queryable().Count(); + } + } + + public class BaseDao + { + + public SqlSugar.SqlSugarClient db { get { return GetInstance(); } } + public void BeginTran() + { + db.Ado.BeginTran(); + } + public void CommitTran() + { + db.Ado.CommitTran(); + } + public void RollbackTran() + { + db.Ado.RollbackTran(); + } + public SqlSugarClient GetInstance() + { + SqlSugarClient db = new SqlSugarClient( + new ConnectionConfig() { + ConnectionString = Config.ConnectionString, + DbType = DbType.SqlServer, + IsAutoCloseConnection = false, + IsShardSameThread= true /*Shard Same Thread*/ + }); + + return db; + } + } +} diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Program.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Program.cs index 6ed75eb28..8fad6514c 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Program.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Program.cs @@ -37,6 +37,8 @@ namespace SqlSeverTest OrmTest.Demo.Filter.Init(); OrmTest.Demo.ComplexModel.Init(); OrmTest.Demo.CodeFirst.Init(); + OrmTest.Demo.MasterSlave.Init(); + OrmTest.Demo.SharedConnection.Init(); } } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/AdoProvider/AdoProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/AdoProvider/AdoProvider.cs index 7fcb4faf9..1fa244f01 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/AdoProvider/AdoProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/AdoProvider/AdoProvider.cs @@ -75,7 +75,7 @@ namespace SqlSugar { this.Connection.Close(); } - if (this.IsMasterSlaveSeparation) + if (this.IsMasterSlaveSeparation && this.SlaveConnections.HasValue()) { foreach (var slaveConnection in this.SlaveConnections) { @@ -263,7 +263,7 @@ namespace SqlSugar if (this.IsClearParameters) sqlCommand.Parameters.Clear(); ExecuteAfter(sql, parameters); - SetConnectionEnd(); + SetConnectionEnd(sql); return count; } catch (Exception ex) @@ -293,7 +293,7 @@ namespace SqlSugar if (this.IsClearParameters) sqlCommand.Parameters.Clear(); ExecuteAfter(sql, parameters); - SetConnectionEnd(); + SetConnectionEnd(sql); return sqlDataReader; } catch (Exception ex) @@ -319,7 +319,7 @@ namespace SqlSugar if (this.IsClearParameters) sqlCommand.Parameters.Clear(); ExecuteAfter(sql, parameters); - SetConnectionEnd(); + SetConnectionEnd(sql); return ds; } catch (Exception ex) @@ -347,7 +347,7 @@ namespace SqlSugar if (this.IsClearParameters) sqlCommand.Parameters.Clear(); ExecuteAfter(sql, parameters); - SetConnectionEnd(); + SetConnectionEnd(sql); return scalar; } catch (Exception ex) @@ -719,9 +719,9 @@ namespace SqlSugar return result.Count() == 0; } - private void SetConnectionEnd() + private void SetConnectionEnd(string sql) { - if (this.IsMasterSlaveSeparation) + if (this.IsMasterSlaveSeparation && IsRead(sql)) { this.Connection = this.MasterConnection; this.Context.CurrentConnectionConfig.ConnectionString = this.MasterConnection.ConnectionString; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConnectionConfig.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConnectionConfig.cs index b1fef35a2..20b783ff7 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConnectionConfig.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConnectionConfig.cs @@ -25,6 +25,10 @@ namespace SqlSugar /// public InitKeyType InitKeyType = InitKeyType.SystemTable; /// + ///If true, there is only one connection instance in the same thread within the same connection string + /// + public bool IsShardSameThread { get; set; } + /// /// Configure External Services replace default services,For example, Redis storage /// [JsonIgnore] diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/SqlSugarAccessory.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/SqlSugarAccessory.cs index 75e71265c..49e6803fe 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/SqlSugarAccessory.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/SqlSugarAccessory.cs @@ -10,7 +10,38 @@ namespace SqlSugar public partial class SqlSugarAccessory { #region Properties - public SqlSugarClient Context { get; set; } + public SqlSugarClient Context + { + get + { + var result = _Context; ; + if (CurrentConnectionConfig.IsShardSameThread) + { + if (CallContext.ContextList.Value.IsNullOrEmpty()) + { + CallContext.ContextList.Value = new List(); + CallContext.ContextList.Value.Add(_Context); + } + else + { + var cacheContext = CallContext.ContextList.Value.FirstOrDefault(it => + it.CurrentConnectionConfig.ConnectionString == _Context.CurrentConnectionConfig.ConnectionString && + it.CurrentConnectionConfig.DbType == _Context.CurrentConnectionConfig.DbType && + it.CurrentConnectionConfig.IsAutoCloseConnection == _Context.CurrentConnectionConfig.IsAutoCloseConnection && + it.CurrentConnectionConfig.IsShardSameThread == _Context.CurrentConnectionConfig.IsShardSameThread); + if (cacheContext != null) + { + return cacheContext; + } + } + } + return result; + } + set + { + _Context = value; + } + } public ConnectionConfig CurrentConnectionConfig { get; set; } public Dictionary TempItems { get; set; } public bool IsSystemTablesConfig { get { return this.CurrentConnectionConfig.InitKeyType == InitKeyType.SystemTable; } } @@ -22,6 +53,7 @@ namespace SqlSugar #region Fields protected ISqlBuilder _SqlBuilder; + public SqlSugarClient _Context { get; set; } protected EntityMaintenance _EntityProvider; protected IAdo _Ado; protected ILambdaExpressions _LambdaExpressions; @@ -287,7 +319,7 @@ namespace SqlSugar else { isJoinType = false; - joinValue += joinValue==null?item:(","+item); + joinValue += joinValue == null ? item : ("," + item); } if (isLast) { diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs index 84fad66c9..48a4090a1 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs @@ -28,7 +28,7 @@ namespace SqlSugar } catch (Exception ex) { - Check.Exception(true, "MySql.Data.dll Nuget更新到 6.10.3-rc 版本的(Core 2.0只支持当前版本), 再检查连接字符串是否正确,{0}", ex.Message); + Check.Exception(true, "MySql.Data.dll Nuget更新到 6.10.4 版本的(Core 2.0只支持当前版本), 再检查连接字符串是否正确,{0}", ex.Message); } } return base._DbConnection; diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugar.csproj b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugar.csproj index 34159a548..32654779c 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugar.csproj +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugar.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 4.5.9.5 + 4.5.9.6 sun_kai_xuan https://github.com/sunkaixuan/SqlSugar @@ -13,7 +13,7 @@ - + diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs index bd58429b8..d5fc40bd7 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs @@ -22,6 +22,7 @@ namespace SqlSugar { base.Context = this; base.CurrentConnectionConfig = config; + base.ContextID = Guid.NewGuid(); Check.ArgumentNullException(config, "config is null"); switch (config.DbType) { @@ -50,41 +51,41 @@ namespace SqlSugar { get { - if (_Ado == null) + if (base.Context._Ado == null) { - var reval = InstanceFactory.GetAdo(base.CurrentConnectionConfig); - _Ado = reval; - reval.Context = this; + var reval = InstanceFactory.GetAdo(base.Context.CurrentConnectionConfig); + base.Context._Ado = reval; + reval.Context = base.Context; return reval; } - return _Ado; + return base.Context._Ado; } } #endregion #region Aop Log Methods - public virtual AopProvider Aop { get { return new AopProvider(this.Context); } } + public virtual AopProvider Aop { get { return new AopProvider(base.Context); } } #endregion #region Util Methods [Obsolete("Use SqlSugarClient.Utilities")] public virtual IContextMethods RewritableMethods { - get { return this.Utilities; } - set { this.Utilities = value; } + get { return base.Context.Utilities; } + set { base.Context.Utilities = value; } } public virtual IContextMethods Utilities { get { - if (base._RewritableMethods == null) + if (base.Context._RewritableMethods == null) { - base._RewritableMethods = new ContextMethods(); - base._RewritableMethods.Context = this; + base.Context._RewritableMethods = new ContextMethods(); + base.Context._RewritableMethods.Context = base.Context; } - return _RewritableMethods; + return base.Context._RewritableMethods; } - set { base._RewritableMethods = value; } + set { base.Context._RewritableMethods = value; } } #endregion @@ -313,7 +314,7 @@ namespace SqlSugar public virtual ISugarQueryable UnionAll(params ISugarQueryable[] queryables) where T : class, new() { - var sqlBuilder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig); + var sqlBuilder = InstanceFactory.GetSqlbuilder(base.Context.CurrentConnectionConfig); Check.Exception(queryables.IsNullOrEmpty(), "UnionAll.queryables is null "); int i = 1; List>> allItems = new List>>(); @@ -330,7 +331,7 @@ namespace SqlSugar } var allSql = sqlBuilder.GetUnionAllSql(allItems.Select(it => it.Key).ToList()); var allParameters = allItems.SelectMany(it => it.Value).ToArray(); - var resulut = this.Queryable().AS(UtilMethods.GetPackTable(allSql, "unionTable")); + var resulut = base.Context.Queryable().AS(UtilMethods.GetPackTable(allSql, "unionTable")); resulut.AddParameters(allParameters); return resulut.Select("*"); } @@ -344,8 +345,8 @@ namespace SqlSugar #region SqlQueryable public ISugarQueryable SqlQueryable(string sql) where T : class, new() { - var sqlBuilder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig); - return this.Queryable().AS(sqlBuilder.GetPackTable(sql, sqlBuilder.GetDefaultShortName())).Select("*"); + var sqlBuilder = InstanceFactory.GetSqlbuilder(base.Context.CurrentConnectionConfig); + return base.Context.Queryable().AS(sqlBuilder.GetPackTable(sql, sqlBuilder.GetDefaultShortName())).Select("*"); } #endregion @@ -359,33 +360,33 @@ namespace SqlSugar public virtual IInsertable Insertable(List insertObjs) where T : class, new() { Check.ArgumentNullException(insertObjs, "Insertable.insertObjs can't be null"); - return this.Insertable(insertObjs.ToArray()); + return base.Context.Insertable(insertObjs.ToArray()); } public virtual IInsertable Insertable(T insertObj) where T : class, new() { - return this.Insertable(new T[] { insertObj }); + return base.Context.Insertable(new T[] { insertObj }); } public virtual IInsertable Insertable(Dictionary columnDictionary) where T : class, new() { InitMppingInfo(); Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Insertable.columnDictionary can't be null"); - var insertObject = this.Utilities.DeserializeObject(this.Utilities.SerializeObject(columnDictionary)); + var insertObject = base.Context.Utilities.DeserializeObject(base.Context.Utilities.SerializeObject(columnDictionary)); var columns = columnDictionary.Select(it => it.Key).ToList(); - return this.Insertable(insertObject).InsertColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); ; + return base.Context.Insertable(insertObject).InsertColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); ; } public virtual IInsertable Insertable(dynamic insertDynamicObject) where T : class, new() { InitMppingInfo(); if (insertDynamicObject is T) { - return this.Insertable((T)insertDynamicObject); + return base.Context.Insertable((T)insertDynamicObject); } else { var columns = ((object)insertDynamicObject).GetType().GetProperties().Select(it => it.Name).ToList(); Check.Exception(columns.IsNullOrEmpty(), "Insertable.updateDynamicObject can't be null"); - T insertObject = this.Utilities.DeserializeObject(this.Utilities.SerializeObject(insertDynamicObject)); - return this.Insertable(insertObject).InsertColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); + T insertObject = base.Context.Utilities.DeserializeObject(base.Context.Utilities.SerializeObject(insertDynamicObject)); + return base.Context.Insertable(insertObject).InsertColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); } } #endregion @@ -400,32 +401,32 @@ namespace SqlSugar public virtual IDeleteable Deleteable(Expression> expression) where T : class, new() { InitMppingInfo(); - return this.Deleteable().Where(expression); + return base.Context.Deleteable().Where(expression); } public virtual IDeleteable Deleteable(dynamic primaryKeyValue) where T : class, new() { InitMppingInfo(); - return this.Deleteable().In(primaryKeyValue); + return base.Context.Deleteable().In(primaryKeyValue); } public virtual IDeleteable Deleteable(dynamic[] primaryKeyValues) where T : class, new() { InitMppingInfo(); - return this.Deleteable().In(primaryKeyValues); + return base.Context.Deleteable().In(primaryKeyValues); } public virtual IDeleteable Deleteable(List pkValue) where T : class, new() { InitMppingInfo(); - return this.Deleteable().In(pkValue); + return base.Context.Deleteable().In(pkValue); } public virtual IDeleteable Deleteable(T deleteObj) where T : class, new() { InitMppingInfo(); - return this.Deleteable().Where(deleteObj); + return base.Context.Deleteable().Where(deleteObj); } public virtual IDeleteable Deleteable(List deleteObjs) where T : class, new() { InitMppingInfo(); - return this.Deleteable().Where(deleteObjs); + return base.Context.Deleteable().Where(deleteObjs); } #endregion @@ -443,33 +444,33 @@ namespace SqlSugar } public virtual IUpdateable Updateable(T UpdateObj) where T : class, new() { - return this.Updateable(new T[] { UpdateObj }); + return base.Context.Updateable(new T[] { UpdateObj }); } public virtual IUpdateable Updateable() where T : class, new() { - return this.Updateable(new T[] { new T() }); + return base.Context.Updateable(new T[] { new T() }); } public virtual IUpdateable Updateable(Dictionary columnDictionary) where T : class, new() { InitMppingInfo(); Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Updateable.columnDictionary can't be null"); - var updateObject = this.Utilities.DeserializeObject(this.Utilities.SerializeObject(columnDictionary)); + var updateObject = base.Context.Utilities.DeserializeObject(base.Context.Utilities.SerializeObject(columnDictionary)); var columns = columnDictionary.Select(it => it.Key).ToList(); - return this.Updateable(updateObject).UpdateColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); ; + return base.Context.Updateable(updateObject).UpdateColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); ; } public virtual IUpdateable Updateable(dynamic updateDynamicObject) where T : class, new() { InitMppingInfo(); if (updateDynamicObject is T) { - return this.Updateable((T)updateDynamicObject); + return base.Context.Updateable((T)updateDynamicObject); } else { var columns = ((object)updateDynamicObject).GetType().GetProperties().Select(it => it.Name).ToList(); Check.Exception(columns.IsNullOrEmpty(), "Updateable.updateDynamicObject can't be null"); - T updateObject = this.Utilities.DeserializeObject(this.Utilities.SerializeObject(updateDynamicObject)); - return this.Updateable(updateObject).UpdateColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); ; + T updateObject = base.Context.Utilities.DeserializeObject(base.Context.Utilities.SerializeObject(updateDynamicObject)); + return base.Context.Updateable(updateObject).UpdateColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); ; } } #endregion @@ -479,8 +480,8 @@ namespace SqlSugar { get { - IDbFirst dbFirst = InstanceFactory.GetDbFirst(this.Context.CurrentConnectionConfig); - dbFirst.Context = this.Context; + IDbFirst dbFirst = InstanceFactory.GetDbFirst(base.Context.CurrentConnectionConfig); + dbFirst.Context = base.Context; dbFirst.Init(); return dbFirst; } @@ -492,8 +493,8 @@ namespace SqlSugar { get { - ICodeFirst codeFirst = InstanceFactory.GetCodeFirst(this.Context.CurrentConnectionConfig); - codeFirst.Context = this.Context; + ICodeFirst codeFirst = InstanceFactory.GetCodeFirst(base.Context.CurrentConnectionConfig); + codeFirst.Context = base.Context; return codeFirst; } } @@ -504,13 +505,13 @@ namespace SqlSugar { get { - if (base._DbMaintenance == null) + if (base.Context._DbMaintenance == null) { - IDbMaintenance maintenance = InstanceFactory.GetDbMaintenance(this.Context.CurrentConnectionConfig); - base._DbMaintenance = maintenance; - maintenance.Context = this.Context; + IDbMaintenance maintenance = InstanceFactory.GetDbMaintenance(base.Context.CurrentConnectionConfig); + base.Context._DbMaintenance = maintenance; + maintenance.Context = base.Context; } - return base._DbMaintenance; + return base.Context._DbMaintenance; } } #endregion @@ -519,21 +520,21 @@ namespace SqlSugar [Obsolete("Use SqlSugarClient.EntityMaintenance")] public virtual EntityMaintenance EntityProvider { - get { return this.EntityMaintenance; } - set { this.EntityMaintenance = value; } + get { return base.Context.EntityMaintenance; } + set { base.Context.EntityMaintenance = value; } } public virtual EntityMaintenance EntityMaintenance { get { - if (base._EntityProvider == null) + if (base.Context._EntityProvider == null) { - base._EntityProvider = new EntityMaintenance(); - base._EntityProvider.Context = this; + base.Context._EntityProvider = new EntityMaintenance(); + base.Context._EntityProvider.Context = base.Context; } - return _EntityProvider; + return base.Context._EntityProvider; } - set { base._EntityProvider = value; } + set { base.Context._EntityProvider = value; } } #endregion @@ -542,14 +543,14 @@ namespace SqlSugar { get { - if (base._QueryFilterProvider == null) + if (base.Context._QueryFilterProvider == null) { - base._QueryFilterProvider = new QueryFilterProvider(); - base._QueryFilterProvider.Context = this; + base.Context._QueryFilterProvider = new QueryFilterProvider(); + base.Context._QueryFilterProvider.Context = base.Context; } - return _QueryFilterProvider; + return base.Context._QueryFilterProvider; } - set { base._QueryFilterProvider = value; } + set { base.Context._QueryFilterProvider = value; } } #endregion @@ -558,9 +559,9 @@ namespace SqlSugar { get { - if (_SimpleClient == null) - _SimpleClient = new SimpleClient(this); - return _SimpleClient; + if (base.Context._SimpleClient == null) + base.Context._SimpleClient = new SimpleClient(base.Context); + return base.Context._SimpleClient; } } #endregion @@ -568,13 +569,13 @@ namespace SqlSugar #region Dispose OR Close public virtual void Close() { - if (this.Ado != null) - this.Ado.Close(); + if (base.Context.Ado != null) + base.Context.Ado.Close(); } public virtual void Dispose() { - if (this.Ado != null) - this.Ado.Dispose(); + if (base.Context.Ado != null) + base.Context.Ado.Dispose(); } #endregion } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCore.nuspec b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCore.nuspec index 0c5350151..3dbebc397 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCore.nuspec +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCore.nuspec @@ -2,7 +2,7 @@ sqlSugarCore - 4.5.9.5 + 4.5.9.6 sunkaixuan Landa http://www.apache.org/licenses/LICENSE-2.0.html @@ -19,6 +19,7 @@ + diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/CallContext.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/CallContext.cs new file mode 100644 index 000000000..5e9cd3280 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/CallContext.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Common; +using System.Linq; +using System.Text; +using System.Threading; + +namespace SqlSugar +{ + internal class CallContext + { + public static ThreadLocal> ContextList = new ThreadLocal>(); + } +} diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/DataBase/SqlSugar4xTest.sqlite b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/DataBase/SqlSugar4xTest.sqlite index ba5ade34b..7f2fc679f 100644 Binary files a/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/DataBase/SqlSugar4xTest.sqlite and b/Src/Asp.NetCore2/SqlSeverTest/SqliteTest/DataBase/SqlSugar4xTest.sqlite differ