mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-22 20:13:41 +08:00
Add db.Ado.UseTran()
This commit is contained in:
@@ -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>();
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user