mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Update db.UseTranAsync
This commit is contained in:
parent
34ddcc5568
commit
48e3935ac4
@ -14,10 +14,10 @@ namespace SqlSugar
|
|||||||
void ChangeDatabase(dynamic configId);
|
void ChangeDatabase(dynamic configId);
|
||||||
void ChangeDatabase(Func<ConnectionConfig, bool> changeExpression);
|
void ChangeDatabase(Func<ConnectionConfig, bool> changeExpression);
|
||||||
DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack = null);
|
DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack = null);
|
||||||
Task<DbResult<bool>> UseTranAsync(Action action, Action<Exception> errorCallBack = null);
|
Task<DbResult<bool>> UseTranAsync(Func<Task> action, Action<Exception> errorCallBack = null);
|
||||||
DbResult<T> UseTran<T>(Func<T> action, Action<Exception> errorCallBack = null);
|
DbResult<T> UseTran<T>(Func<T> action, Action<Exception> errorCallBack = null);
|
||||||
|
|
||||||
Task<DbResult<T>> UseTranAsync<T>(Func<T> action, Action<Exception> errorCallBack = null);
|
Task<DbResult<T>> UseTranAsync<T>(Func<Task<T>> action, Action<Exception> errorCallBack = null);
|
||||||
void AddConnection(ConnectionConfig connection);
|
void AddConnection(ConnectionConfig connection);
|
||||||
SqlSugarProvider GetConnection(dynamic configId);
|
SqlSugarProvider GetConnection(dynamic configId);
|
||||||
bool IsAnyConnection(dynamic configId);
|
bool IsAnyConnection(dynamic configId);
|
||||||
|
@ -687,9 +687,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)
|
||||||
@ -717,9 +737,30 @@ namespace SqlSugar
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<DbResult<T>> UseTranAsync<T>(Func<T> action, Action<Exception> errorCallBack = null)
|
public async Task<DbResult<T>> UseTranAsync<T>(Func<Task<T>> action, Action<Exception> errorCallBack = null)
|
||||||
{
|
{
|
||||||
return Task.FromResult(UseTran(action, errorCallBack));
|
var result = new DbResult<T>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.BeginTran();
|
||||||
|
T data=default(T);
|
||||||
|
if (action != null)
|
||||||
|
data = await action();
|
||||||
|
this.CommitTran();
|
||||||
|
result.Data = data;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
result.ErrorException = ex;
|
||||||
|
result.ErrorMessage = ex.Message;
|
||||||
|
result.IsSuccess = false;
|
||||||
|
this.RollbackTran();
|
||||||
|
if (errorCallBack != null)
|
||||||
|
{
|
||||||
|
errorCallBack(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RollbackTran()
|
public void RollbackTran()
|
||||||
|
@ -662,12 +662,12 @@ namespace SqlSugar
|
|||||||
return ScopedContext.UseTran(action,errorCallBack);
|
return ScopedContext.UseTran(action,errorCallBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<DbResult<bool>> UseTranAsync(Action action, Action<Exception> errorCallBack = null)
|
public Task<DbResult<bool>> UseTranAsync(Func<Task> action, Action<Exception> errorCallBack = null)
|
||||||
{
|
{
|
||||||
return ScopedContext.UseTranAsync(action, errorCallBack);
|
return ScopedContext.UseTranAsync(action, errorCallBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<DbResult<T>> UseTranAsync<T>(Func<T> action, Action<Exception> errorCallBack = null)
|
public Task<DbResult<T>> UseTranAsync<T>(Func<Task<T>> action, Action<Exception> errorCallBack = null)
|
||||||
{
|
{
|
||||||
return ScopedContext.UseTranAsync(action, errorCallBack);
|
return ScopedContext.UseTranAsync(action, errorCallBack);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user