Add db.UseTran(+0)

This commit is contained in:
sunkaixuna
2021-09-01 00:28:25 +08:00
parent 17ec6c40e7
commit 41bc3c53dd
5 changed files with 33 additions and 1 deletions

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public class SqlSguarTransaction
{
private readonly SqlSugarClient context;
public SqlSguarTransaction(SqlSugarClient client)
{
context = client;
context.BeginTran();
}
public void Dispose()
{
context.RollbackTran();
}
}
}

View File

@@ -13,6 +13,7 @@ namespace SqlSugar
void RollbackTran();
void ChangeDatabase(dynamic configId);
void ChangeDatabase(Func<ConnectionConfig, bool> changeExpression);
SqlSguarTransaction UseTran();
DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack = null);
Task<DbResult<bool>> UseTranAsync(Func<Task> action, Action<Exception> errorCallBack = null);
DbResult<T> UseTran<T>(Func<T> action, Action<Exception> errorCallBack = null);

View File

@@ -88,6 +88,7 @@
<Compile Include="Abstract\FilterProvider\FilterProvider.cs" />
<Compile Include="Abstract\InsertableProvider\InsertableProvider.cs" />
<Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" />
<Compile Include="Entities\SqlSguarTransaction.cs" />
<Compile Include="ExpressionsToSql\Subquery\Items\SubAs.cs" />
<Compile Include="Interface\ISugarRepository.cs" />
<Compile Include="Interface\IParameterInsertable.cs" />

View File

@@ -575,6 +575,10 @@ namespace SqlSugar
#endregion
#region TenantManager
public SqlSguarTransaction UseTran()
{
return new SqlSguarTransaction(this);
}
public void AddConnection(ConnectionConfig connection)
{
Check.ArgumentNullException(connection, "AddConnection.connection can't be null");

View File

@@ -651,7 +651,10 @@ namespace SqlSugar
{
return ScopedContext.Updateable(UpdateObjs);
}
public SqlSguarTransaction UseTran()
{
return ScopedContext.UseTran();
}
public DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack = null)
{
return ScopedContext.UseTran(action,errorCallBack);