mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-27 11:19:15 +08:00
Synchronization code
This commit is contained in:
@@ -13,14 +13,24 @@ namespace SqlSugar
|
|||||||
public class SqlSugarScopeProvider:ISqlSugarClient
|
public class SqlSugarScopeProvider:ISqlSugarClient
|
||||||
{
|
{
|
||||||
internal SqlSugarProvider conn;
|
internal SqlSugarProvider conn;
|
||||||
|
internal string initThreadMainId;
|
||||||
|
internal string initkey = null;
|
||||||
StackFrame[] frames;
|
StackFrame[] frames;
|
||||||
|
|
||||||
public SqlSugarScopeProvider(SqlSugarProvider conn)
|
public SqlSugarScopeProvider(SqlSugarProvider conn)
|
||||||
{
|
{
|
||||||
this.conn = conn;
|
this.conn = conn;
|
||||||
|
this.initThreadMainId = GetCurrentThreadId();
|
||||||
var key = GetKey();
|
var key = GetKey();
|
||||||
|
this.initkey = key;
|
||||||
this.GetContext(true);
|
this.GetContext(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetCurrentThreadId()
|
||||||
|
{
|
||||||
|
return System.Threading.Thread.CurrentThread.ManagedThreadId + "";
|
||||||
|
}
|
||||||
|
|
||||||
public SqlSugarProvider ScopedContext { get { return GetContext(); } }
|
public SqlSugarProvider ScopedContext { get { return GetContext(); } }
|
||||||
private SqlSugarProvider GetAsyncContext(bool isInit=false)
|
private SqlSugarProvider GetAsyncContext(bool isInit=false)
|
||||||
{
|
{
|
||||||
@@ -89,6 +99,10 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
private dynamic GetKey()
|
private dynamic GetKey()
|
||||||
{
|
{
|
||||||
|
if (!string.IsNullOrEmpty(this.initkey) &&this.initThreadMainId == GetCurrentThreadId())
|
||||||
|
{
|
||||||
|
return this.initkey;
|
||||||
|
}
|
||||||
var key= "SqlSugarProviderScope_" + conn.CurrentConnectionConfig.ConfigId;
|
var key= "SqlSugarProviderScope_" + conn.CurrentConnectionConfig.ConfigId;
|
||||||
if (frames == null)
|
if (frames == null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user