sqlSugarCore CallContext不允许访问使用了,怎么办 返回

热忱回答(6)
-
fate stay night VIP0
2018/10/19这个是私有类,底层就是
https://github.com/sunkaixuan/SqlSugar/blob/dev/Src/Asp.Net/SqlSugar/Utilities/CallContext.cs
0 回复 -
fate stay night VIP0
2018/10/19用我现成的功能就好了
SqlSugarClient db = new SqlSugarClient( new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true, IsShardSameThread= true //设为true相同线程是同一个SqlConnection }); return db;0 回复 -
゛Mr.℡_鵬 VIP0
2018/10/19
@fate stay night:我想通过不同的构造函数初始化不同的连接,怎么写?
0 回复 -
fate stay night VIP0
2018/10/19把我这个类自个建一个 https://github.com/sunkaixuan/SqlSugar/blob/dev/Src/Asp.Net/SqlSugar/Utilities/CallContext.cs
0 回复 -
゛Mr.℡_鵬 VIP0
2018/10/19public static class CallContext
{
static ConcurrentDictionary<string, AsyncLocal<object>> state = new ConcurrentDictionary<string, AsyncLocal<object>>();
public static void SetData(string name, object data) =>
state.GetOrAdd(name, _ => new AsyncLocal<object>()).Value = data;
public static object GetData(string name) =>
state.TryGetValue(name, out AsyncLocal<object> data) ? data.Value : null;
}
@fate stay night:
0 回复 -
゛Mr.℡_鵬 VIP0
2018/10/19@fate stay night:网上的解决方案,这样可以吗
0 回复