diff --git a/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs index 27adf36ae..f75b1ff56 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs @@ -185,7 +185,7 @@ namespace SqlSugar #endregion #region Use - public DbResult UseTran(Action action) + public DbResult UseTran(Action action, Action errorCallBack=null) { var result = new DbResult(); 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> UseTranAsync(Action action) + public Task> UseTranAsync(Action action, Action errorCallBack = null) { Task> result = new Task>(() => { - return UseTran(action); + return UseTran(action,errorCallBack); }); TaskStart(result); return result; } - public DbResult UseTran(Func action) + public DbResult UseTran(Func action, Action errorCallBack = null) { var result = new DbResult(); 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> UseTranAsync(Func action) + public Task> UseTranAsync(Func action, Action errorCallBack = null) { Task> result = new Task>(() => { - return UseTran(action); + return UseTran(action,errorCallBack); }); TaskStart(result); return result; diff --git a/Src/Asp.Net/SqlSugar/Interface/IAdo.cs b/Src/Asp.Net/SqlSugar/Interface/IAdo.cs index d8a38be0e..5f8b1dda4 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IAdo.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IAdo.cs @@ -95,10 +95,10 @@ namespace SqlSugar void RollbackTran(); void CommitTran(); - DbResult UseTran(Action action); - DbResult UseTran(Func action); - Task> UseTranAsync(Action action); - Task> UseTranAsync(Func action); + DbResult UseTran(Action action, Action errorCallBack = null); + DbResult UseTran(Func action, Action errorCallBack = null); + Task> UseTranAsync(Action action, Action errorCallBack = null); + Task> UseTranAsync(Func action, Action errorCallBack = null); void UseStoredProcedure(Action action); T UseStoredProcedure(Func action);