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();
|
CheckConnection();
|
||||||
}
|
}
|
||||||
|
public virtual async Task OpenAsync()
|
||||||
|
{
|
||||||
|
await CheckConnectionAsync();
|
||||||
|
}
|
||||||
public SugarConnection OpenAlways()
|
public SugarConnection OpenAlways()
|
||||||
{
|
{
|
||||||
SugarConnection result = new SugarConnection();
|
SugarConnection result = new SugarConnection();
|
||||||
@ -132,6 +136,27 @@ namespace SqlSugar
|
|||||||
this.Open();
|
this.Open();
|
||||||
return result;
|
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()
|
public virtual void Close()
|
||||||
{
|
{
|
||||||
if (this.Transaction != null)
|
if (this.Transaction != null)
|
||||||
|
@ -174,7 +174,9 @@ namespace SqlSugar
|
|||||||
|
|
||||||
void Dispose();
|
void Dispose();
|
||||||
void Close();
|
void Close();
|
||||||
|
Task CloseAsync();
|
||||||
void Open();
|
void Open();
|
||||||
|
Task OpenAsync();
|
||||||
SugarConnection OpenAlways();
|
SugarConnection OpenAlways();
|
||||||
bool IsValidConnection();
|
bool IsValidConnection();
|
||||||
bool IsValidConnectionNoClose();
|
bool IsValidConnectionNoClose();
|
||||||
|
Loading…
Reference in New Issue
Block a user