mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 01:58:13 +08:00
Update db.ado.UseTranAsync
This commit is contained in:
@@ -214,9 +214,29 @@ namespace SqlSugar
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<DbResult<bool>> UseTranAsync(Action action, Action<Exception> errorCallBack = null)
|
public async Task<DbResult<bool>> UseTranAsync(Func<Task> action, Action<Exception> errorCallBack = null)
|
||||||
{
|
{
|
||||||
return Task.FromResult(UseTran(action, errorCallBack));
|
var result = new DbResult<bool>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.BeginTran();
|
||||||
|
if (action != null)
|
||||||
|
await action();
|
||||||
|
this.CommitTran();
|
||||||
|
result.Data = result.IsSuccess = true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
result.ErrorException = ex;
|
||||||
|
result.ErrorMessage = ex.Message;
|
||||||
|
result.IsSuccess = false;
|
||||||
|
this.RollbackTran();
|
||||||
|
if (errorCallBack != null)
|
||||||
|
{
|
||||||
|
errorCallBack(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DbResult<T> UseTran<T>(Func<T> action, Action<Exception> errorCallBack = null)
|
public DbResult<T> UseTran<T>(Func<T> action, Action<Exception> errorCallBack = null)
|
||||||
|
Reference in New Issue
Block a user