diff --git a/Src/Asp.Net/SqlSugar/Interface/ITenant.cs b/Src/Asp.Net/SqlSugar/Interface/ITenant.cs index b0561e770..1f2bf0088 100644 --- a/Src/Asp.Net/SqlSugar/Interface/ITenant.cs +++ b/Src/Asp.Net/SqlSugar/Interface/ITenant.cs @@ -10,5 +10,7 @@ namespace SqlSugar void BeginAllTran(); void CommitAllTran(); void RollbackAllTran(); + void ChangeDatabase(string configId); + void ChangeDatabase(Func changeExpression); } } diff --git a/Src/Asp.Net/SqlSugar/SqlSugarClient.cs b/Src/Asp.Net/SqlSugar/SqlSugarClient.cs index b254e405b..a996288a5 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.Net/SqlSugar/SqlSugarClient.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; namespace SqlSugar { - public class SqlSugarClient : ISqlSugarClient, ITenant + public partial class SqlSugarClient : ISqlSugarClient, ITenant { #region Gobal Property private ISqlSugarClient _Context = null; @@ -24,8 +24,7 @@ namespace SqlSugar #endregion - - public ISqlSugarClient Context { get => GetContext(); set => _Context = value; } + #region Constructor public SqlSugarClient(ConnectionConfig config) { Check.Exception(config == null, "ConnectionConfig config is null"); @@ -42,119 +41,23 @@ namespace SqlSugar _AllClients.First(it => it.ConnectionConfig.ConfigId == config.ConfigId).Context = this.Context; } - public void ChangeDatabase(string configId) - { - Check.Exception(!_AllClients.Any(it => it.ConnectionConfig.ConfigId == configId), "ConfigId was not found {0}", configId); - InitTenant(_AllClients.First(it => it.ConnectionConfig.ConfigId == configId)); - if (this._IsAllTran) - this.Ado.BeginTran(); - } - public void ChangeDatabase(Func changeExpression) - { - var allConfigs = _AllClients.Select(it => it.ConnectionConfig); - Check.Exception(!allConfigs.Any(changeExpression), "changeExpression was not found {0}", changeExpression.ToString()); - InitTenant(_AllClients.First(it=>it.ConnectionConfig==allConfigs.First(changeExpression))); - if (this._IsAllTran) - this.Ado.BeginTran(); - } + #endregion + + #region Global variable + public ISqlSugarClient Context { get => GetContext(); set => _Context = value; } + public bool IsSystemTablesConfig => this.Context.IsSystemTablesConfig; + public ConnectionConfig CurrentConnectionConfig { get => _CurrentConnectionConfig; set => _CurrentConnectionConfig = value; } + public Guid ContextID { get => this.Context.ContextID; set => this.Context.ContextID = value; } public MappingTableList MappingTables { get => _MappingTables; set => _MappingTables = value; } public MappingColumnList MappingColumns { get => _MappingColumns; set => _MappingColumns = value; } public IgnoreColumnList IgnoreColumns { get => _IgnoreColumns; set => _IgnoreColumns = value; } public IgnoreColumnList IgnoreInsertColumns { get => _IgnoreInsertColumns; set => _IgnoreInsertColumns = value; } - - public ConnectionConfig CurrentConnectionConfig { get => _CurrentConnectionConfig; set => _CurrentConnectionConfig = value; } - - - - - public QueueList Queues { get => this.Context.Queues; set => this.Context.Queues = value; } - public Dictionary TempItems { get => this.Context.TempItems; set => this.Context.TempItems = value; } - public IContextMethods Utilities { get => this.Context.Utilities; set => this.Context.Utilities = value; } - public IAdo Ado => this.Context.Ado; - - public AopProvider Aop => this.Context.Aop; - - public ICodeFirst CodeFirst => this.Context.CodeFirst; - - public Guid ContextID { get => this.Context.ContextID; set => this.Context.ContextID = value; } - - - public IDbFirst DbFirst => this.Context.DbFirst; - - public IDbMaintenance DbMaintenance => this.Context.DbMaintenance; - - public EntityMaintenance EntityMaintenance { get => this.Context.EntityMaintenance; set => this.Context.EntityMaintenance = value; } - - - public bool IsSystemTablesConfig => this.Context.IsSystemTablesConfig; - - public QueryFilterProvider QueryFilter { get => this.Context.QueryFilter; set => this.Context.QueryFilter = value; } - - - public void AddQueue(string sql, object parsmeters = null) - { - this.Context.AddQueue(sql, parsmeters); - } - - public void AddQueue(string sql, List parsmeters) - { - this.Context.AddQueue(sql, parsmeters); - } - - public void AddQueue(string sql, SugarParameter parsmeter) - { - this.Context.AddQueue(sql, parsmeter); - } - - public void Close() - { - this.Context.Close(); - } - - public IDeleteable Deleteable() where T : class, new() - { - return this.Context.Deleteable(); - } - - public IDeleteable Deleteable(dynamic primaryKeyValue) where T : class, new() - { - return this.Context.Deleteable(primaryKeyValue); - } - - public IDeleteable Deleteable(dynamic[] primaryKeyValues) where T : class, new() - { - return this.Context.Deleteable(primaryKeyValues); - } - - public IDeleteable Deleteable(Expression> expression) where T : class, new() - { - return this.Context.Deleteable(expression); - } - - public IDeleteable Deleteable(List pkValue) where T : class, new() - { - return this.Context.Deleteable(pkValue); - } - - public IDeleteable Deleteable(List deleteObjs) where T : class, new() - { - return this.Context.Deleteable(deleteObjs); - } - - public IDeleteable Deleteable(T deleteObj) where T : class, new() - { - return this.Context.Deleteable(deleteObj); - } - - - public DateTime GetDate() - { - return this.Context.GetDate(); - } + #endregion + #region SimpleClient public SimpleClient GetSimpleClient() { return this.Context.GetSimpleClient(); @@ -164,15 +67,7 @@ namespace SqlSugar { return this.Context.GetSimpleClient(); } - - public void InitMppingInfo(Type type) - { - this.Context.InitMppingInfo(type); - } - public void InitMppingInfo() - { - this.Context.InitMppingInfo(typeof(T)); - } + #endregion #region Insertable public IInsertable Insertable(Dictionary columnDictionary) where T : class, new() @@ -201,12 +96,31 @@ namespace SqlSugar } #endregion - public void Open() + + #region Queryable + + #region Union + public ISugarQueryable Union(List> queryables) where T : class, new() { - this.Context.Open(); + return this.Context.Union(queryables); } - #region Queryable + public ISugarQueryable Union(params ISugarQueryable[] queryables) where T : class, new() + { + return this.Context.Union(queryables); + } + + public ISugarQueryable UnionAll(List> queryables) where T : class, new() + { + return this.Context.UnionAll(queryables); + } + + public ISugarQueryable UnionAll(params ISugarQueryable[] queryables) where T : class, new() + { + return this.Context.UnionAll(queryables); + } + #endregion + public ISugarQueryable SqlQueryable(string sql) where T : class, new() { return this.Context.SqlQueryable(sql); @@ -425,6 +339,21 @@ namespace SqlSugar #endregion #region Queue + public QueueList Queues { get => this.Context.Queues; set => this.Context.Queues = value; } + public void AddQueue(string sql, object parsmeters = null) + { + this.Context.AddQueue(sql, parsmeters); + } + + public void AddQueue(string sql, List parsmeters) + { + this.Context.AddQueue(sql, parsmeters); + } + + public void AddQueue(string sql, SugarParameter parsmeter) + { + this.Context.AddQueue(sql, parsmeter); + } public int SaveQueues(bool isTran = true) { return this.Context.SaveQueues(isTran); @@ -503,29 +432,7 @@ namespace SqlSugar public Task> SaveQueuesAsync(bool isTran = true) { return this.Context.SaveQueuesAsync(isTran); - } - #endregion - - #region Union - public ISugarQueryable Union(List> queryables) where T : class, new() - { - return this.Context.Union(queryables); - } - - public ISugarQueryable Union(params ISugarQueryable[] queryables) where T : class, new() - { - return this.Context.Union(queryables); } - - public ISugarQueryable UnionAll(List> queryables) where T : class, new() - { - return this.Context.UnionAll(queryables); - } - - public ISugarQueryable UnionAll(params ISugarQueryable[] queryables) where T : class, new() - { - return this.Context.UnionAll(queryables); - } #endregion #region Updateable @@ -571,7 +478,85 @@ namespace SqlSugar #endregion + #region Ado + public IAdo Ado => this.Context.Ado; + + public void Close() + { + this.Context.Close(); + } + public void Open() + { + this.Context.Open(); + } + + #endregion + + #region Deleteable + public IDeleteable Deleteable() where T : class, new() + { + return this.Context.Deleteable(); + } + + public IDeleteable Deleteable(dynamic primaryKeyValue) where T : class, new() + { + return this.Context.Deleteable(primaryKeyValue); + } + + public IDeleteable Deleteable(dynamic[] primaryKeyValues) where T : class, new() + { + return this.Context.Deleteable(primaryKeyValues); + } + + public IDeleteable Deleteable(Expression> expression) where T : class, new() + { + return this.Context.Deleteable(expression); + } + + public IDeleteable Deleteable(List pkValue) where T : class, new() + { + return this.Context.Deleteable(pkValue); + } + + public IDeleteable Deleteable(List deleteObjs) where T : class, new() + { + return this.Context.Deleteable(deleteObjs); + } + + public IDeleteable Deleteable(T deleteObj) where T : class, new() + { + return this.Context.Deleteable(deleteObj); + } + + + #endregion + + #region More api + public IContextMethods Utilities { get => this.Context.Utilities; set => this.Context.Utilities = value; } + public AopProvider Aop => this.Context.Aop; + public ICodeFirst CodeFirst => this.Context.CodeFirst; + public IDbFirst DbFirst => this.Context.DbFirst; + public IDbMaintenance DbMaintenance => this.Context.DbMaintenance; + public EntityMaintenance EntityMaintenance { get => this.Context.EntityMaintenance; set => this.Context.EntityMaintenance = value; } + public QueryFilterProvider QueryFilter { get => this.Context.QueryFilter; set => this.Context.QueryFilter = value; } + #endregion + #region ITenant + public void ChangeDatabase(string configId) + { + Check.Exception(!_AllClients.Any(it => it.ConnectionConfig.ConfigId == configId), "ConfigId was not found {0}", configId); + InitTenant(_AllClients.First(it => it.ConnectionConfig.ConfigId == configId)); + if (this._IsAllTran) + this.Ado.BeginTran(); + } + public void ChangeDatabase(Func changeExpression) + { + var allConfigs = _AllClients.Select(it => it.ConnectionConfig); + Check.Exception(!allConfigs.Any(changeExpression), "changeExpression was not found {0}", changeExpression.ToString()); + InitTenant(_AllClients.First(it => it.ConnectionConfig == allConfigs.First(changeExpression))); + if (this._IsAllTran) + this.Ado.BeginTran(); + } public void BeginAllTran() { _IsAllTran = true; @@ -610,6 +595,21 @@ namespace SqlSugar #endregion + #region Other method + public DateTime GetDate() + { + return this.Context.GetDate(); + } + public void InitMppingInfo(Type type) + { + this.Context.InitMppingInfo(type); + } + public void InitMppingInfo() + { + this.Context.InitMppingInfo(typeof(T)); + } + #endregion + #region Helper private ISqlSugarClient GetContext() { @@ -736,5 +736,6 @@ namespace SqlSugar [Obsolete] public SimpleClient SimpleClient => this.Context.SimpleClient; #endregion + } }