mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-26 10:19:40 +08:00
Add db.Ado.UseTran()
This commit is contained in:
@@ -287,6 +287,10 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Use
|
#region Use
|
||||||
|
public SqlSugarTransactionAdo UseTran()
|
||||||
|
{
|
||||||
|
return new SqlSugarTransactionAdo(this.Context);
|
||||||
|
}
|
||||||
public DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack = null)
|
public DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack = null)
|
||||||
{
|
{
|
||||||
var result = new DbResult<bool>();
|
var result = new DbResult<bool>();
|
||||||
|
|||||||
@@ -28,4 +28,26 @@ namespace SqlSugar
|
|||||||
context.RollbackTran();
|
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();
|
Task RollbackTranAsync();
|
||||||
void CommitTran();
|
void CommitTran();
|
||||||
Task CommitTranAsync();
|
Task CommitTranAsync();
|
||||||
|
SqlSugarTransactionAdo UseTran();
|
||||||
DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack = null);
|
DbResult<bool> UseTran(Action 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<bool>> UseTranAsync(Func<Task> action, Action<Exception> errorCallBack = null);
|
Task<DbResult<bool>> UseTranAsync(Func<Task> action, Action<Exception> errorCallBack = null);
|
||||||
|
|||||||
Reference in New Issue
Block a user