Synchronization code

This commit is contained in:
sunkaixuan 2022-11-26 15:41:32 +08:00
parent 57db09375b
commit 1c210f048d
3 changed files with 22 additions and 0 deletions

View File

@ -21,6 +21,7 @@ namespace SqlSugar
Task<DbResult<T>> UseTranAsync<T>(Func<Task<T>> action, Action<Exception> errorCallBack = null);
void AddConnection(ConnectionConfig connection);
SqlSugarProvider GetConnection(dynamic configId);
void RemoveConnection(string configId);
SqlSugarScopeProvider GetConnectionScope(dynamic configId);
SqlSugarProvider GetConnectionWithAttr<T>();
SqlSugarScopeProvider GetConnectionScopeWithAttr<T>();

View File

@ -777,6 +777,23 @@ namespace SqlSugar
{
return new SqlSugarTransaction(this);
}
public void RemoveConnection(string configId)
{
var removeData= this._AllClients.FirstOrDefault(it => it.ConnectionConfig.ConfigId.ObjToString()== configId.ObjToString());
var currentId= this.CurrentConnectionConfig.ConfigId;
if (removeData != null)
{
if (removeData.Context.Ado.IsAnyTran())
{
Check.ExceptionEasy("RemoveConnection error has tran",$"删除失败{removeData.ConnectionConfig.ConfigId}存在未提交事务");
}
else if (removeData.ConnectionConfig.ConfigId.ObjToString()== currentId.ObjToString())
{
Check.ExceptionEasy("Default ConfigId cannot be deleted", $"默认库不能删除{removeData.ConnectionConfig.ConfigId}");
}
this._AllClients.Remove(removeData);
}
}
public void AddConnection(ConnectionConfig connection)
{
Check.ArgumentNullException(connection, "AddConnection.connection can't be null");

View File

@ -793,5 +793,9 @@ namespace SqlSugar
{
ScopedContext.Tracking(datas);
}
public void RemoveConnection(string configId)
{
ScopedContext.RemoveConnection(configId);
}
}
}