mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Add OpenAsync CloseAsync
This commit is contained in:
parent
15c193f22f
commit
afdece575c
@ -122,6 +122,10 @@ namespace SqlSugar
|
||||
{
|
||||
CheckConnection();
|
||||
}
|
||||
public virtual async Task OpenAsync()
|
||||
{
|
||||
await CheckConnectionAsync();
|
||||
}
|
||||
public SugarConnection OpenAlways()
|
||||
{
|
||||
SugarConnection result = new SugarConnection();
|
||||
@ -132,6 +136,27 @@ namespace SqlSugar
|
||||
this.Open();
|
||||
return result;
|
||||
}
|
||||
public async Task CloseAsync()
|
||||
{
|
||||
if (this.Transaction != null)
|
||||
{
|
||||
this.Transaction = null;
|
||||
}
|
||||
if (this.Connection != null && this.Connection.State == ConnectionState.Open)
|
||||
{
|
||||
await ((DbConnection)this.Connection).CloseAsync();
|
||||
}
|
||||
if (this.IsMasterSlaveSeparation && this.SlaveConnections.HasValue())
|
||||
{
|
||||
foreach (var slaveConnection in this.SlaveConnections)
|
||||
{
|
||||
if (slaveConnection != null && slaveConnection.State == ConnectionState.Open)
|
||||
{
|
||||
await ((DbConnection)slaveConnection).CloseAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public virtual void Close()
|
||||
{
|
||||
if (this.Transaction != null)
|
||||
|
@ -174,7 +174,9 @@ namespace SqlSugar
|
||||
|
||||
void Dispose();
|
||||
void Close();
|
||||
Task CloseAsync();
|
||||
void Open();
|
||||
Task OpenAsync();
|
||||
SugarConnection OpenAlways();
|
||||
bool IsValidConnection();
|
||||
bool IsValidConnectionNoClose();
|
||||
|
Loading…
Reference in New Issue
Block a user