Add db.Ado.UseTran()

This commit is contained in:
sunkaixuan
2024-06-18 18:39:39 +08:00
parent f6df34f0dc
commit ff645535ab
3 changed files with 27 additions and 1 deletions

View File

@@ -287,6 +287,10 @@ namespace SqlSugar
#endregion
#region Use
public SqlSugarTransactionAdo UseTran()
{
return new SqlSugarTransactionAdo(this.Context);
}
public DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack = null)
{
var result = new DbResult<bool>();

View File

@@ -28,4 +28,26 @@ namespace SqlSugar
context.RollbackTran();
}
}
public class SqlSugarTransactionAdo : IDisposable
{
private readonly ISqlSugarClient context;
public SqlSugarTransactionAdo(ISqlSugarClient client)
{
context = client;
context.Ado.BeginTran();
}
public void CommitTran()
{
context.Ado.CommitTran();
}
public void RollbackTran()
{
context.Ado.RollbackTran();
}
public void Dispose()
{
context.Ado.RollbackTran();
}
}
}

View File

@@ -185,7 +185,7 @@ namespace SqlSugar
Task RollbackTranAsync();
void CommitTran();
Task CommitTranAsync();
SqlSugarTransactionAdo UseTran();
DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack = null);
DbResult<T> UseTran<T>(Func<T> action, Action<Exception> errorCallBack = null);
Task<DbResult<bool>> UseTranAsync(Func<Task> action, Action<Exception> errorCallBack = null);