|
|
@ -627,7 +627,7 @@ namespace SqlSugar |
|
|
|
public void RollbackTran() |
|
|
|
{ |
|
|
|
this.Context.Ado.RollbackTran(); |
|
|
|
AllClientEach(it=>it.Ado.RollbackTran()); |
|
|
|
AllClientEach(it => it.Ado.RollbackTran()); |
|
|
|
_IsAllTran = false; |
|
|
|
} |
|
|
|
public void Close() |
|
|
@ -671,7 +671,44 @@ namespace SqlSugar |
|
|
|
#region Helper
|
|
|
|
private SqlSugarProvider GetContext() |
|
|
|
{ |
|
|
|
if (CurrentConnectionConfig.IsShardSameThread) |
|
|
|
if (IsOnleySharedSameThread()) |
|
|
|
return SharedSameThread(); |
|
|
|
else if (IsSingleAndSharedThread()) |
|
|
|
return SingleAndSharedThread(); |
|
|
|
else if (IsSynchronization()) |
|
|
|
return Synchronization(); |
|
|
|
else |
|
|
|
return Single(); |
|
|
|
} |
|
|
|
|
|
|
|
private SqlSugarProvider Single() |
|
|
|
{ |
|
|
|
if (CallContext.ContextList.Value == null) |
|
|
|
{ |
|
|
|
CallContext.ContextList.Value = new List<SqlSugarProvider>(); |
|
|
|
} |
|
|
|
if (CallContext.ContextList.Value.IsNullOrEmpty() || GetCallContext() == null) |
|
|
|
{ |
|
|
|
var context = CopyClient(); |
|
|
|
CallContext.ContextList.Value.Add(context); |
|
|
|
return context; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
return GetCallContext(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private SqlSugarProvider Synchronization() |
|
|
|
{ |
|
|
|
_Context.MappingColumns = _MappingColumns; |
|
|
|
_Context.MappingTables = _MappingTables; |
|
|
|
_Context.IgnoreColumns = _IgnoreColumns; |
|
|
|
_Context.IgnoreInsertColumns = _IgnoreInsertColumns; |
|
|
|
return _Context; |
|
|
|
} |
|
|
|
|
|
|
|
private SqlSugarProvider SingleAndSharedThread() |
|
|
|
{ |
|
|
|
SqlSugarProvider result = _Context; |
|
|
|
if (CallContext.ContextList.Value.IsNullOrEmpty()) |
|
|
@ -695,31 +732,45 @@ namespace SqlSugar |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
else if (_ThreadId == Thread.CurrentThread.ManagedThreadId.ToString()) |
|
|
|
|
|
|
|
private SqlSugarProvider SharedSameThread() |
|
|
|
{ |
|
|
|
_Context.MappingColumns = _MappingColumns; |
|
|
|
_Context.MappingTables = _MappingTables; |
|
|
|
_Context.IgnoreColumns = _IgnoreColumns; |
|
|
|
_Context.IgnoreInsertColumns = _IgnoreInsertColumns; |
|
|
|
return _Context; |
|
|
|
SqlSugarProvider result = _Context; |
|
|
|
if (CallContext.ContextList.Value.IsNullOrEmpty()) |
|
|
|
{ |
|
|
|
|
|
|
|
CallContext.ContextList.Value = new List<SqlSugarProvider>(); |
|
|
|
CallContext.ContextList.Value.Add(_Context); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (CallContext.ContextList.Value == null) |
|
|
|
SqlSugarProvider cacheContext = GetCallContext(); |
|
|
|
if (cacheContext != null) |
|
|
|
{ |
|
|
|
CallContext.ContextList.Value = new List<SqlSugarProvider>(); |
|
|
|
result = cacheContext; |
|
|
|
} |
|
|
|
if (CallContext.ContextList.Value.IsNullOrEmpty() || GetCallContext() == null) |
|
|
|
else |
|
|
|
{ |
|
|
|
var context = CopyClient(); |
|
|
|
CallContext.ContextList.Value.Add(context); |
|
|
|
return context; |
|
|
|
result = CopyClient(); |
|
|
|
CallContext.ContextList.Value.Add(result); |
|
|
|
} |
|
|
|
else |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private bool IsSynchronization() |
|
|
|
{ |
|
|
|
return GetCallContext(); |
|
|
|
return _ThreadId == Thread.CurrentThread.ManagedThreadId.ToString(); |
|
|
|
} |
|
|
|
|
|
|
|
private bool IsSingleAndSharedThread() |
|
|
|
{ |
|
|
|
return CurrentConnectionConfig.IsShardSameThread && _ThreadId != Thread.CurrentThread.ManagedThreadId.ToString(); |
|
|
|
} |
|
|
|
|
|
|
|
private bool IsOnleySharedSameThread() |
|
|
|
{ |
|
|
|
return CurrentConnectionConfig.IsShardSameThread && _ThreadId == Thread.CurrentThread.ManagedThreadId.ToString(); |
|
|
|
} |
|
|
|
|
|
|
|
private SqlSugarProvider CopyClient() |
|
|
@ -736,9 +787,9 @@ namespace SqlSugar |
|
|
|
private SqlSugarProvider GetCallContext() |
|
|
|
{ |
|
|
|
return CallContext.ContextList.Value.FirstOrDefault(it => |
|
|
|
it.CurrentConnectionConfig.DbType == _Context.CurrentConnectionConfig.DbType&& |
|
|
|
it.CurrentConnectionConfig.ConnectionString == _Context.CurrentConnectionConfig.ConnectionString&& |
|
|
|
it.CurrentConnectionConfig.InitKeyType==_Context.CurrentConnectionConfig.InitKeyType&& |
|
|
|
it.CurrentConnectionConfig.DbType == _Context.CurrentConnectionConfig.DbType && |
|
|
|
it.CurrentConnectionConfig.ConnectionString == _Context.CurrentConnectionConfig.ConnectionString && |
|
|
|
it.CurrentConnectionConfig.InitKeyType == _Context.CurrentConnectionConfig.InitKeyType && |
|
|
|
it.CurrentConnectionConfig.IsAutoCloseConnection == _Context.CurrentConnectionConfig.IsAutoCloseConnection |
|
|
|
); |
|
|
|
} |
|
|
|