diff --git a/Src/Asp.Net/SqlSugar/ScopedClient.cs b/Src/Asp.Net/SqlSugar/ScopedClient.cs index 3310ae76a..4d5c31f48 100644 --- a/Src/Asp.Net/SqlSugar/ScopedClient.cs +++ b/Src/Asp.Net/SqlSugar/ScopedClient.cs @@ -1,10 +1,616 @@ -using System.Text; +using System; +using System.Collections.Generic; +using System.Dynamic; +using System.Linq.Expressions; +using System.Text; using System.Threading.Tasks; namespace SqlSugar { - //public class ScopedClient : ISqlSugarClient, ITenant - //{ + public class ScopedClient : ISqlSugarClient, ITenant + { + private SqlSugarClient db; + private ScopedClient() + { - //} + } + public ScopedClient(SqlSugarClient context) + { + this.db = context; + } + public SqlSugarClient ScopedContext + { + get + { + var key = db.GetHashCode().ToString(); + SqlSugarClient result = CallContextAsync.GetData(key); + if (result == null) + { + CallContextAsync.SetData(key, new SqlSugarClient(db._allConfigs)); + result = CallContextAsync.GetData(key); + } + return result; + } + } + public MappingTableList MappingTables { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public MappingColumnList MappingColumns { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public IgnoreColumnList IgnoreColumns { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public IgnoreColumnList IgnoreInsertColumns { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public Dictionary TempItems { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public ConfigQuery ConfigQuery { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + + public bool IsSystemTablesConfig => throw new NotImplementedException(); + + public Guid ContextID { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public ConnectionConfig CurrentConnectionConfig { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + + public IAdo Ado => throw new NotImplementedException(); + + public AopProvider Aop => throw new NotImplementedException(); + + public ICodeFirst CodeFirst => throw new NotImplementedException(); + + public IDbFirst DbFirst => throw new NotImplementedException(); + + public IDbMaintenance DbMaintenance => throw new NotImplementedException(); + + public EntityMaintenance EntityMaintenance { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public QueryFilterProvider QueryFilter { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public IContextMethods Utilities { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public QueueList Queues { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + + public SugarCacheProvider DataCache => throw new NotImplementedException(); + + public void AddConnection(ConnectionConfig connection) + { + throw new NotImplementedException(); + } + + public void AddQueue(string sql, object parsmeters = null) + { + throw new NotImplementedException(); + } + + public void AddQueue(string sql, List parsmeters) + { + throw new NotImplementedException(); + } + + public void AddQueue(string sql, SugarParameter parsmeter) + { + throw new NotImplementedException(); + } + + public void BeginTran() + { + throw new NotImplementedException(); + } + + public void ChangeDatabase(dynamic configId) + { + throw new NotImplementedException(); + } + + public void ChangeDatabase(Func changeExpression) + { + throw new NotImplementedException(); + } + + public void Close() + { + throw new NotImplementedException(); + } + + public void CommitTran() + { + throw new NotImplementedException(); + } + + public IDeleteable Deleteable() where T : class, new() + { + throw new NotImplementedException(); + } + + public IDeleteable Deleteable(dynamic primaryKeyValue) where T : class, new() + { + throw new NotImplementedException(); + } + + public IDeleteable Deleteable(dynamic[] primaryKeyValues) where T : class, new() + { + throw new NotImplementedException(); + } + + public IDeleteable Deleteable(Expression> expression) where T : class, new() + { + throw new NotImplementedException(); + } + + public IDeleteable Deleteable(List pkValue) where T : class, new() + { + throw new NotImplementedException(); + } + + public IDeleteable Deleteable(List deleteObjs) where T : class, new() + { + throw new NotImplementedException(); + } + + public IDeleteable Deleteable(T deleteObj) where T : class, new() + { + throw new NotImplementedException(); + } + + public void Dispose() + { + throw new NotImplementedException(); + } + + public SqlSugarProvider GetConnection(dynamic configId) + { + throw new NotImplementedException(); + } + + public DateTime GetDate() + { + throw new NotImplementedException(); + } + + public SimpleClient GetSimpleClient() where T : class, new() + { + throw new NotImplementedException(); + } + + public void InitMappingInfo(Type type) + { + throw new NotImplementedException(); + } + + public void InitMappingInfo() + { + throw new NotImplementedException(); + } + + public IInsertable Insertable(Dictionary columnDictionary) where T : class, new() + { + throw new NotImplementedException(); + } + + public IInsertable Insertable(dynamic insertDynamicObject) where T : class, new() + { + throw new NotImplementedException(); + } + + public IInsertable Insertable(List insertObjs) where T : class, new() + { + throw new NotImplementedException(); + } + + public IInsertable Insertable(T insertObj) where T : class, new() + { + throw new NotImplementedException(); + } + + public IInsertable Insertable(T[] insertObjs) where T : class, new() + { + throw new NotImplementedException(); + } + + public void Open() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(string tableName, string shortName) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(Expression> joinExpression) + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(ISugarQueryable joinQueryable1, ISugarQueryable joinQueryable2, Expression> joinExpression) + where T : class, new() + where T2 : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(ISugarQueryable joinQueryable1, ISugarQueryable joinQueryable2, JoinType joinType, Expression> joinExpression) + where T : class, new() + where T2 : class, new() + { + throw new NotImplementedException(); + } + + 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() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(ISugarQueryable queryable) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Queryable(string shortName) + { + throw new NotImplementedException(); + } + + public IReportable Reportable(T data) + { + throw new NotImplementedException(); + } + + public IReportable Reportable(List list) + { + throw new NotImplementedException(); + } + + public IReportable Reportable(T[] array) + { + throw new NotImplementedException(); + } + + public void RollbackTran() + { + throw new NotImplementedException(); + } + + public ISaveable Saveable(List saveObjects) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISaveable Saveable(T saveObject) where T : class, new() + { + throw new NotImplementedException(); + } + + public int SaveQueues(bool isTran = true) + { + throw new NotImplementedException(); + } + + public Tuple, List, List, List, List, List, List> SaveQueues(bool isTran = true) + { + throw new NotImplementedException(); + } + + public Tuple, List, List, List, List, List> SaveQueues(bool isTran = true) + { + throw new NotImplementedException(); + } + + public Tuple, List, List, List, List> SaveQueues(bool isTran = true) + { + throw new NotImplementedException(); + } + + public Tuple, List, List, List> SaveQueues(bool isTran = true) + { + throw new NotImplementedException(); + } + + public Tuple, List, List> SaveQueues(bool isTran = true) + { + throw new NotImplementedException(); + } + + public Tuple, List> SaveQueues(bool isTran = true) + { + throw new NotImplementedException(); + } + + public List SaveQueues(bool isTran = true) + { + throw new NotImplementedException(); + } + + public Task SaveQueuesAsync(bool isTran = true) + { + throw new NotImplementedException(); + } + + public Task, List, List, List, List, List, List>> SaveQueuesAsync(bool isTran = true) + { + throw new NotImplementedException(); + } + + public Task, List, List, List, List, List>> SaveQueuesAsync(bool isTran = true) + { + throw new NotImplementedException(); + } + + public Task, List, List, List, List>> SaveQueuesAsync(bool isTran = true) + { + throw new NotImplementedException(); + } + + public Task, List, List, List>> SaveQueuesAsync(bool isTran = true) + { + throw new NotImplementedException(); + } + + public Task, List, List>> SaveQueuesAsync(bool isTran = true) + { + throw new NotImplementedException(); + } + + public Task, List>> SaveQueuesAsync(bool isTran = true) + { + throw new NotImplementedException(); + } + + public Task> SaveQueuesAsync(bool isTran = true) + { + throw new NotImplementedException(); + } + + public ISugarQueryable SqlQueryable(string sql) where T : class, new() + { + throw new NotImplementedException(); + } + + public IStorageable Storageable(List dataList) where T : class, new() + { + throw new NotImplementedException(); + } + + public IStorageable Storageable(T data) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Union(List> queryables) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable Union(params ISugarQueryable[] queryables) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable UnionAll(List> queryables) where T : class, new() + { + throw new NotImplementedException(); + } + + public ISugarQueryable UnionAll(params ISugarQueryable[] queryables) where T : class, new() + { + throw new NotImplementedException(); + } + + public IUpdateable Updateable() where T : class, new() + { + throw new NotImplementedException(); + } + + public IUpdateable Updateable(Dictionary columnDictionary) where T : class, new() + { + throw new NotImplementedException(); + } + + public IUpdateable Updateable(dynamic updateDynamicObject) where T : class, new() + { + throw new NotImplementedException(); + } + + public IUpdateable Updateable(Expression> columns) where T : class, new() + { + throw new NotImplementedException(); + } + + public IUpdateable Updateable(Expression> columns) where T : class, new() + { + throw new NotImplementedException(); + } + + public IUpdateable Updateable(List UpdateObjs) where T : class, new() + { + throw new NotImplementedException(); + } + + public IUpdateable Updateable(T UpdateObj) where T : class, new() + { + throw new NotImplementedException(); + } + + public IUpdateable Updateable(T[] UpdateObjs) where T : class, new() + { + throw new NotImplementedException(); + } + + public DbResult UseTran(Action action, Action errorCallBack = null) + { + throw new NotImplementedException(); + } + + public DbResult UseTran(Func action, Action errorCallBack = null) + { + throw new NotImplementedException(); + } + + public Task> UseTranAsync(Action action, Action errorCallBack = null) + { + throw new NotImplementedException(); + } + + public Task> UseTranAsync(Func action, Action errorCallBack = null) + { + throw new NotImplementedException(); + } + } } diff --git a/Src/Asp.Net/SqlSugar/SqlSugarClient.cs b/Src/Asp.Net/SqlSugar/SqlSugarClient.cs index 1aa553583..3aa405f21 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.Net/SqlSugar/SqlSugarClient.cs @@ -25,18 +25,21 @@ namespace SqlSugar private IgnoreColumnList _IgnoreInsertColumns; internal Guid? AsyncId { get; set; } internal bool? IsSingleInstance { get; set; } + internal List _allConfigs { get; set; } #endregion #region Constructor public SqlSugarClient(ConnectionConfig config) { + _allConfigs = new List() { config }; Check.Exception(config == null, "ConnectionConfig config is null"); InitContext(config); } public SqlSugarClient(List configs) { + _allConfigs = configs; Check.Exception(configs.IsNullOrEmpty(), "List configs is null"); InitConfigs(configs); var config = configs.First();