Browse Source

Update UseTran

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
fbc455a643
  1. 20
      Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
  2. 8
      Src/Asp.Net/SqlSugar/Interface/IAdo.cs

20
Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs

@ -185,7 +185,7 @@ namespace SqlSugar
#endregion
#region Use
public DbResult<bool> UseTran(Action action)
public DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack=null)
{
var result = new DbResult<bool>();
try
@ -202,21 +202,25 @@ namespace SqlSugar
result.ErrorMessage = ex.Message;
result.IsSuccess = false;
this.RollbackTran();
if (errorCallBack != null)
{
errorCallBack(ex);
}
}
return result;
}
public Task<DbResult<bool>> UseTranAsync(Action action)
public Task<DbResult<bool>> UseTranAsync(Action action, Action<Exception> errorCallBack = null)
{
Task<DbResult<bool>> result = new Task<DbResult<bool>>(() =>
{
return UseTran(action);
return UseTran(action,errorCallBack);
});
TaskStart(result);
return result;
}
public DbResult<T> UseTran<T>(Func<T> action)
public DbResult<T> UseTran<T>(Func<T> action, Action<Exception> errorCallBack = null)
{
var result = new DbResult<T>();
try
@ -233,15 +237,19 @@ namespace SqlSugar
result.ErrorMessage = ex.Message;
result.IsSuccess = false;
this.RollbackTran();
if (errorCallBack != null)
{
errorCallBack(ex);
}
}
return result;
}
public Task<DbResult<T>> UseTranAsync<T>(Func<T> action)
public Task<DbResult<T>> UseTranAsync<T>(Func<T> action, Action<Exception> errorCallBack = null)
{
Task<DbResult<T>> result = new Task<DbResult<T>>(() =>
{
return UseTran(action);
return UseTran(action,errorCallBack);
});
TaskStart(result);
return result;

8
Src/Asp.Net/SqlSugar/Interface/IAdo.cs

@ -95,10 +95,10 @@ namespace SqlSugar
void RollbackTran();
void CommitTran();
DbResult<bool> UseTran(Action action);
DbResult<T> UseTran<T>(Func<T> action);
Task<DbResult<bool>> UseTranAsync(Action action);
Task<DbResult<T>> UseTranAsync<T>(Func<T> action);
DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack = null);
DbResult<T> UseTran<T>(Func<T> action, Action<Exception> errorCallBack = null);
Task<DbResult<bool>> UseTranAsync(Action action, Action<Exception> errorCallBack = null);
Task<DbResult<T>> UseTranAsync<T>(Func<T> action, Action<Exception> errorCallBack = null);
void UseStoredProcedure(Action action);
T UseStoredProcedure<T>(Func<T> action);

Loading…
Cancel
Save