diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/ExpressionableProvider/Expressionable.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/ExpressionableProvider/Expressionable.cs index b4f095875..b69618282 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/ExpressionableProvider/Expressionable.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/ExpressionableProvider/Expressionable.cs @@ -271,6 +271,138 @@ namespace SqlSugar return _exp; } } + public class Expressionable where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new() where T7 : class, new() + { + Expression> _exp = null; + + public Expressionable And(Expression> exp) + { + if (_exp == null) + _exp = exp; + else + _exp = Expression.Lambda>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters); + return this; + } + + public Expressionable AndIF(bool isAnd, Expression> exp) + { + if (isAnd) + And(exp); + return this; + } + + public Expressionable Or(Expression> exp) + { + if (_exp == null) + _exp = exp; + else + _exp = Expression.Lambda>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters); + return this; + } + + public Expressionable OrIF(bool isOr, Expression> exp) + { + if (isOr) + Or(exp); + return this; + } + + + public Expression> ToExpression() + { + if (_exp == null) + _exp = (it, t2, t3, t4, T5, t6,t7) => true; + return _exp; + } + } + public class Expressionable where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new() where T7 : class, new() where T8 : class, new() + { + Expression> _exp = null; + + public Expressionable And(Expression> exp) + { + if (_exp == null) + _exp = exp; + else + _exp = Expression.Lambda>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters); + return this; + } + + public Expressionable AndIF(bool isAnd, Expression> exp) + { + if (isAnd) + And(exp); + return this; + } + + public Expressionable Or(Expression> exp) + { + if (_exp == null) + _exp = exp; + else + _exp = Expression.Lambda>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters); + return this; + } + + public Expressionable OrIF(bool isOr, Expression> exp) + { + if (isOr) + Or(exp); + return this; + } + + + public Expression> ToExpression() + { + if (_exp == null) + _exp = (it, t2, t3, t4, T5, t6, t7,t8) => true; + return _exp; + } + } + public class Expressionable where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new() where T7 : class, new() where T8 : class, new() where T9 : class, new() + { + Expression> _exp = null; + + public Expressionable And(Expression> exp) + { + if (_exp == null) + _exp = exp; + else + _exp = Expression.Lambda>(Expression.AndAlso(_exp.Body, exp.Body), _exp.Parameters); + return this; + } + + public Expressionable AndIF(bool isAnd, Expression> exp) + { + if (isAnd) + And(exp); + return this; + } + + public Expressionable Or(Expression> exp) + { + if (_exp == null) + _exp = exp; + else + _exp = Expression.Lambda>(Expression.OrElse(_exp.Body, exp.Body), _exp.Parameters); + return this; + } + + public Expressionable OrIF(bool isOr, Expression> exp) + { + if (isOr) + Or(exp); + return this; + } + + + public Expression> ToExpression() + { + if (_exp == null) + _exp = (it, t2, t3, t4, T5, t6, t7, t8,t9) => true; + return _exp; + } + } public class Expressionable { public static Expressionable Create() where T : class, new() @@ -297,5 +429,17 @@ namespace SqlSugar { return new Expressionable(); } + public static Expressionable Create() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new() where T7 : class, new() + { + return new Expressionable(); + } + public static Expressionable Create() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new() where T7 : class, new() where T8 : class, new() + { + return new Expressionable(); + } + public static Expressionable Create() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new() where T7 : class, new() where T8 : class, new() where T9 : class, new() + { + return new Expressionable(); + } } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/Reportable/ReportableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/Reportable/ReportableProvider.cs index e183fa7a3..848786939 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/Reportable/ReportableProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/Reportable/ReportableProvider.cs @@ -137,8 +137,8 @@ namespace SqlSugar { if (datas.Count == 1) { - isDates = true; var data=datas.First(); + isDates = data is ReportableDateType; if (data is ReportableDateType) { var type = UtilMethods.ChangeType2(data, typeof(ReportableDateType)); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SaveableProvider/Storageable.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SaveableProvider/Storageable.cs index 414978be6..1b64010fa 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SaveableProvider/Storageable.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SaveableProvider/Storageable.cs @@ -70,6 +70,10 @@ namespace SqlSugar public StorageableResult ToStorage() { + if (whereFuncs == null || whereFuncs.Count == 0) + { + return this.Saveable().ToStorage(); + } if (this.allDatas.Count == 0) return new StorageableResult() { AsDeleteable = this.Context.Deleteable().AS(asname).Where(it => false), diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ISqlSugarClient.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ISqlSugarClient.cs index 856080252..5089d0b16 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ISqlSugarClient.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/ISqlSugarClient.cs @@ -163,6 +163,12 @@ namespace SqlSugar IUpdateable Updateable(T[] UpdateObjs) where T : class, new(); #endregion + #region Reportable + IReportable Reportable(T data); + IReportable Reportable(List list); + IReportable Reportable(T[] array); + #endregion + #region Cache SugarCacheProvider DataCache { get; } #endregion diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCore.nuspec b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCore.nuspec index a98e70655..dbe1c6f9d 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCore.nuspec +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCore.nuspec @@ -2,7 +2,7 @@ SqlSugarCore - 5.0.3.2 + 5.0.3.3 sunkaixuan Landa http://www.apache.org/licenses/LICENSE-2.0.html diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCoreMySqlConnector.nuspec b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCoreMySqlConnector.nuspec index a9298d8b1..531605703 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCoreMySqlConnector.nuspec +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCoreMySqlConnector.nuspec @@ -2,7 +2,7 @@ SqlSugarCore.MySqlConnector - 5.0.3.2 + 5.0.3.3 sunkaixuan Landa http://www.apache.org/licenses/LICENSE-2.0.html diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCoreNoDrive.nuspec b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCoreNoDrive.nuspec index cd3a3a903..2980f03f2 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCoreNoDrive.nuspec +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarForCoreNoDrive.nuspec @@ -2,7 +2,7 @@ SqlSugarCoreNoDrive - 5.0.3.2 + 5.0.3.3 sunkaixuan Landa http://www.apache.org/licenses/LICENSE-2.0.html diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarScope.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarScope.cs new file mode 100644 index 000000000..7cc527745 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarScope.cs @@ -0,0 +1,675 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Dynamic; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; + +namespace SqlSugar +{ + public class SqlSugarScope: ISqlSugarClient, ITenant + { + private List _configs; + private Action _configAction; + private SqlSugarScope() + { + + } + public SqlSugarScope(ConnectionConfig config) + { + _configs=new List() { config}; + } + public SqlSugarScope(List configs) + { + _configs = configs; + } + public SqlSugarScope(ConnectionConfig config, Action configAction) + { + _configs = new List() { config }; + this._configAction = configAction; + } + public SqlSugarScope(List configs, Action configAction) + { + _configs = configs; + this._configAction = configAction; + } + //public ScopedClient(SqlSugarClient context,Action configAction) + //{ + // this.db = context; + // this.configAction = configAction; + //} + public SqlSugarClient ScopedContext + { + get + { + SqlSugarClient result = null; + var key = _configs.GetHashCode().ToString(); + StackTrace st = new StackTrace(true); + var methods = st.GetFrames(); + var isAsync = UtilMethods.IsAnyAsyncMethod(methods); + if (isAsync) + { + result=GetAsyncContext(key); + } + else + { + result = GetThreadContext(key); + } + return result; + } + } + + private SqlSugarClient GetAsyncContext(string key) + { + SqlSugarClient result = CallContextAsync.GetData(key); + if (result == null) + { + CallContextAsync.SetData(key, new SqlSugarClient(_configs)); + result = CallContextAsync.GetData(key); + if (this._configAction != null) + { + this._configAction(result); + } + } + + return result; + } + + private SqlSugarClient GetThreadContext(string key) + { + SqlSugarClient result = CallContextThread.GetData(key); + if (result == null) + { + CallContextThread.SetData(key, new SqlSugarClient(_configs)); + result = CallContextThread.GetData(key); + if (this._configAction != null) + { + this._configAction(result); + } + } + return result; + } + + public MappingTableList MappingTables { get => ScopedContext.MappingTables; set => ScopedContext.MappingTables = value; } + public MappingColumnList MappingColumns { get => ScopedContext.MappingColumns; set => ScopedContext.MappingColumns=value; } + public IgnoreColumnList IgnoreColumns { get => ScopedContext.IgnoreColumns; set => ScopedContext.IgnoreColumns=value; } + public IgnoreColumnList IgnoreInsertColumns { get => ScopedContext.IgnoreInsertColumns; set => ScopedContext.IgnoreInsertColumns=value; } + public Dictionary TempItems { get => ScopedContext.TempItems; set => ScopedContext.TempItems=value; } + public ConfigQuery ConfigQuery { get => ScopedContext.ConfigQuery; set => ScopedContext.ConfigQuery = value; } + + public bool IsSystemTablesConfig => ScopedContext.IsSystemTablesConfig; + + public Guid ContextID { get => ScopedContext.ContextID; set => ScopedContext.ContextID=value; } + public ConnectionConfig CurrentConnectionConfig { get => ScopedContext.CurrentConnectionConfig; set => ScopedContext.CurrentConnectionConfig=value; } + + public IAdo Ado => ScopedContext.Ado; + + public AopProvider Aop => ScopedContext.Aop; + + public ICodeFirst CodeFirst => ScopedContext.CodeFirst; + + public IDbFirst DbFirst => ScopedContext.DbFirst; + + public IDbMaintenance DbMaintenance => ScopedContext.DbMaintenance; + + public EntityMaintenance EntityMaintenance { get => ScopedContext.EntityMaintenance; set => ScopedContext.EntityMaintenance=value; } + public QueryFilterProvider QueryFilter { get => ScopedContext.QueryFilter; set => ScopedContext.QueryFilter=value; } + public IContextMethods Utilities { get => ScopedContext.Utilities; set => ScopedContext.Utilities=value; } + public QueueList Queues { get => ScopedContext.Queues; set => ScopedContext.Queues=value; } + + public SugarCacheProvider DataCache => ScopedContext.DataCache; + + public void AddConnection(ConnectionConfig connection) + { + ScopedContext.AddConnection(connection); + } + + public void AddQueue(string sql, object parsmeters = null) + { + ScopedContext.AddQueue(sql, parsmeters); + } + + public void AddQueue(string sql, List parsmeters) + { + ScopedContext.AddQueue(sql,parsmeters); + } + + public void AddQueue(string sql, SugarParameter parsmeter) + { + ScopedContext.AddQueue(sql,parsmeter); + } + + public void BeginTran() + { + ScopedContext.BeginTran(); + } + + public void ChangeDatabase(dynamic configId) + { + ScopedContext.ChangeDatabase(configId); + } + + public void ChangeDatabase(Func changeExpression) + { + ScopedContext.ChangeDatabase(changeExpression); + } + + public void Close() + { + ScopedContext.Close(); + } + + public void CommitTran() + { + ScopedContext.CommitTran(); + } + + public IDeleteable Deleteable() where T : class, new() + { + return ScopedContext.Deleteable(); + } + + public IDeleteable Deleteable(dynamic primaryKeyValue) where T : class, new() + { + return ScopedContext.Deleteable(primaryKeyValue); + } + + public IDeleteable Deleteable(dynamic[] primaryKeyValues) where T : class, new() + { + return ScopedContext.Deleteable(primaryKeyValues); + } + + public IDeleteable Deleteable(Expression> expression) where T : class, new() + { + return ScopedContext.Deleteable(expression); + } + + public IDeleteable Deleteable(List pkValue) where T : class, new() + { + return ScopedContext.Deleteable(pkValue); + } + + public IDeleteable Deleteable(List deleteObjs) where T : class, new() + { + return ScopedContext.Deleteable(deleteObjs); + } + + public IDeleteable Deleteable(T deleteObj) where T : class, new() + { + return ScopedContext.Deleteable(deleteObj); + } + + public void Dispose() + { + ScopedContext.Dispose(); + } + + public SqlSugarProvider GetConnection(dynamic configId) + { + return ScopedContext.GetConnection(configId); + } + + public DateTime GetDate() + { + return ScopedContext.GetDate(); + } + + public SimpleClient GetSimpleClient() where T : class, new() + { + return ScopedContext.GetSimpleClient(); + } + + public void InitMappingInfo(Type type) + { + ScopedContext.InitMappingInfo(type); + } + + public void InitMappingInfo() + { + ScopedContext.InitMappingInfo(); + } + + public IInsertable Insertable(Dictionary columnDictionary) where T : class, new() + { + return ScopedContext.Insertable(columnDictionary); + } + + public IInsertable Insertable(dynamic insertDynamicObject) where T : class, new() + { + return ScopedContext.Insertable((object)insertDynamicObject); + } + + public IInsertable Insertable(List insertObjs) where T : class, new() + { + return ScopedContext.Insertable(insertObjs); + } + + public IInsertable Insertable(T insertObj) where T : class, new() + { + return ScopedContext.Insertable(insertObj); + } + + public IInsertable Insertable(T[] insertObjs) where T : class, new() + { + return ScopedContext.Insertable(insertObjs); + } + + public void Open() + { + ScopedContext.Open(); + } + + public ISugarQueryable Queryable(string tableName, string shortName) + { + return ScopedContext.Queryable(tableName,shortName); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + return ScopedContext.Queryable(joinExpression); + } + + public ISugarQueryable Queryable(ISugarQueryable joinQueryable1, ISugarQueryable joinQueryable2, Expression> joinExpression) + where T : class, new() + where T2 : class, new() + { + return ScopedContext.Queryable(joinQueryable1,joinQueryable2, joinExpression); + } + + public ISugarQueryable Queryable(ISugarQueryable joinQueryable1, ISugarQueryable joinQueryable2, JoinType joinType, Expression> joinExpression) + where T : class, new() + where T2 : class, new() + { + return ScopedContext.Queryable(joinQueryable1, joinQueryable2, joinType, joinExpression); + } + + public ISugarQueryable Queryable(ISugarQueryable joinQueryable1, ISugarQueryable joinQueryable2, ISugarQueryable joinQueryable3, JoinType joinType1, Expression> joinExpression1, JoinType joinType2, Expression> joinExpression2) + where T : class, new() + where T2 : class, new() + where T3 : class, new() + { + return ScopedContext.Queryable(joinQueryable1, joinQueryable2, joinQueryable3,joinType1,joinExpression1,joinType2,joinExpression2); + } + + public ISugarQueryable Queryable() + { + return ScopedContext.Queryable(); + } + + public ISugarQueryable Queryable(ISugarQueryable queryable) where T : class, new() + { + return ScopedContext.Queryable(queryable); + } + + public ISugarQueryable Queryable(string shortName) + { + return ScopedContext.Queryable(shortName); + } + + public IReportable Reportable(T data) + { + return ScopedContext.Reportable(data); + } + + public IReportable Reportable(List list) + { + return ScopedContext.Reportable(list); + } + + public IReportable Reportable(T[] array) + { + return ScopedContext.Reportable(array); + } + + public void RollbackTran() + { + ScopedContext.RollbackTran(); + } + + public ISaveable Saveable(List saveObjects) where T : class, new() + { + return ScopedContext.Saveable(saveObjects); + } + + public ISaveable Saveable(T saveObject) where T : class, new() + { + return ScopedContext.Saveable(saveObject); + } + + public int SaveQueues(bool isTran = true) + { + return ScopedContext.SaveQueues(isTran); + } + + public Tuple, List, List, List, List, List, List> SaveQueues(bool isTran = true) + { + return ScopedContext.SaveQueues(isTran); + } + + public Tuple, List, List, List, List, List> SaveQueues(bool isTran = true) + { + return ScopedContext.SaveQueues(isTran); + } + + public Tuple, List, List, List, List> SaveQueues(bool isTran = true) + { + return ScopedContext.SaveQueues(isTran); + } + + public Tuple, List, List, List> SaveQueues(bool isTran = true) + { + return ScopedContext.SaveQueues(isTran); + } + + public Tuple, List, List> SaveQueues(bool isTran = true) + { + return ScopedContext.SaveQueues(isTran); + } + + public Tuple, List> SaveQueues(bool isTran = true) + { + return ScopedContext.SaveQueues(isTran); + } + + public List SaveQueues(bool isTran = true) + { + return ScopedContext.SaveQueues(isTran); + } + + public Task SaveQueuesAsync(bool isTran = true) + { + return ScopedContext.SaveQueuesAsync(isTran); + } + + public Task, List, List, List, List, List, List>> SaveQueuesAsync(bool isTran = true) + { + return ScopedContext.SaveQueuesAsync(isTran); + } + + public Task, List, List, List, List, List>> SaveQueuesAsync(bool isTran = true) + { + return ScopedContext.SaveQueuesAsync(isTran); + } + + public Task, List, List, List, List>> SaveQueuesAsync(bool isTran = true) + { + return ScopedContext.SaveQueuesAsync(isTran); + } + + public Task, List, List, List>> SaveQueuesAsync(bool isTran = true) + { + return ScopedContext.SaveQueuesAsync(isTran); + } + + public Task, List, List>> SaveQueuesAsync(bool isTran = true) + { + return ScopedContext.SaveQueuesAsync(isTran); + } + + public Task, List>> SaveQueuesAsync(bool isTran = true) + { + return ScopedContext.SaveQueuesAsync(isTran); + } + + public Task> SaveQueuesAsync(bool isTran = true) + { + return ScopedContext.SaveQueuesAsync(isTran); + } + + public ISugarQueryable SqlQueryable(string sql) where T : class, new() + { + return ScopedContext.SqlQueryable(sql); + } + + public IStorageable Storageable(List dataList) where T : class, new() + { + return ScopedContext.Storageable(dataList); + } + + public IStorageable Storageable(T data) where T : class, new() + { + return ScopedContext.Storageable(data); + } + + public ISugarQueryable Union(List> queryables) where T : class, new() + { + return ScopedContext.Union(queryables); + } + + public ISugarQueryable Union(params ISugarQueryable[] queryables) where T : class, new() + { + return ScopedContext.Union(queryables); + } + + public ISugarQueryable UnionAll(List> queryables) where T : class, new() + { + return ScopedContext.UnionAll(queryables); + } + + public ISugarQueryable UnionAll(params ISugarQueryable[] queryables) where T : class, new() + { + return ScopedContext.UnionAll(queryables); + } + + public IUpdateable Updateable() where T : class, new() + { + return ScopedContext.Updateable(); + } + + public IUpdateable Updateable(Dictionary columnDictionary) where T : class, new() + { + return ScopedContext.Updateable(columnDictionary); + } + + public IUpdateable Updateable(dynamic updateDynamicObject) where T : class, new() + { + return ScopedContext.Updateable((object)updateDynamicObject); + } + + public IUpdateable Updateable(Expression> columns) where T : class, new() + { + return ScopedContext.Updateable(columns); + } + + public IUpdateable Updateable(Expression> columns) where T : class, new() + { + return ScopedContext.Updateable(columns); + } + + public IUpdateable Updateable(List UpdateObjs) where T : class, new() + { + return ScopedContext.Updateable(UpdateObjs); + } + + public IUpdateable Updateable(T UpdateObj) where T : class, new() + { + return ScopedContext.Updateable(UpdateObj); + } + + public IUpdateable Updateable(T[] UpdateObjs) where T : class, new() + { + return ScopedContext.Updateable(UpdateObjs); + } + + public DbResult UseTran(Action action, Action errorCallBack = null) + { + return ScopedContext.UseTran(action,errorCallBack); + } + + public DbResult UseTran(Func action, Action errorCallBack = null) + { + return ScopedContext.UseTran(action,errorCallBack); + } + + public Task> UseTranAsync(Action action, Action errorCallBack = null) + { + return ScopedContext.UseTranAsync(action, errorCallBack); + } + + public Task> UseTranAsync(Func action, Action errorCallBack = null) + { + return ScopedContext.UseTranAsync(action, errorCallBack); + } + } +} diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/CallContextAsync.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/CallContextAsync.cs new file mode 100644 index 000000000..31f128863 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/CallContextAsync.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace SqlSugar +{ + public class CallContextAsync + { + static ConcurrentDictionary> state = new ConcurrentDictionary>(); + public static void SetData(string name, T data) => + state.GetOrAdd(name, _ => new AsyncLocal()).Value = data; + public static T GetData(string name) => + state.TryGetValue(name, out AsyncLocal data) ? data.Value : default(T); + } + + public class CallContextThread + { + static ConcurrentDictionary> state = new ConcurrentDictionary>(); + public static void SetData(string name, T data) => + state.GetOrAdd(name, _ => new ThreadLocal()).Value = data; + public static T GetData(string name) => + state.TryGetValue(name, out ThreadLocal data) ? data.Value : default(T); + } +}