mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-18 17:48:11 +08:00
Add db.UseTran(+0)
This commit is contained in:
23
Src/Asp.Net/SqlSugar/Entities/SqlSguarTransaction.cs
Normal file
23
Src/Asp.Net/SqlSugar/Entities/SqlSguarTransaction.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -13,6 +13,7 @@ namespace SqlSugar
|
|||||||
void RollbackTran();
|
void RollbackTran();
|
||||||
void ChangeDatabase(dynamic configId);
|
void ChangeDatabase(dynamic configId);
|
||||||
void ChangeDatabase(Func<ConnectionConfig, bool> changeExpression);
|
void ChangeDatabase(Func<ConnectionConfig, bool> changeExpression);
|
||||||
|
SqlSguarTransaction UseTran();
|
||||||
DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack = null);
|
DbResult<bool> UseTran(Action 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);
|
||||||
DbResult<T> UseTran<T>(Func<T> action, Action<Exception> errorCallBack = null);
|
DbResult<T> UseTran<T>(Func<T> action, Action<Exception> errorCallBack = null);
|
||||||
|
@@ -88,6 +88,7 @@
|
|||||||
<Compile Include="Abstract\FilterProvider\FilterProvider.cs" />
|
<Compile Include="Abstract\FilterProvider\FilterProvider.cs" />
|
||||||
<Compile Include="Abstract\InsertableProvider\InsertableProvider.cs" />
|
<Compile Include="Abstract\InsertableProvider\InsertableProvider.cs" />
|
||||||
<Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" />
|
<Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" />
|
||||||
|
<Compile Include="Entities\SqlSguarTransaction.cs" />
|
||||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubAs.cs" />
|
<Compile Include="ExpressionsToSql\Subquery\Items\SubAs.cs" />
|
||||||
<Compile Include="Interface\ISugarRepository.cs" />
|
<Compile Include="Interface\ISugarRepository.cs" />
|
||||||
<Compile Include="Interface\IParameterInsertable.cs" />
|
<Compile Include="Interface\IParameterInsertable.cs" />
|
||||||
|
@@ -575,6 +575,10 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region TenantManager
|
#region TenantManager
|
||||||
|
public SqlSguarTransaction UseTran()
|
||||||
|
{
|
||||||
|
return new SqlSguarTransaction(this);
|
||||||
|
}
|
||||||
public void AddConnection(ConnectionConfig connection)
|
public void AddConnection(ConnectionConfig connection)
|
||||||
{
|
{
|
||||||
Check.ArgumentNullException(connection, "AddConnection.connection can't be null");
|
Check.ArgumentNullException(connection, "AddConnection.connection can't be null");
|
||||||
|
@@ -651,7 +651,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return ScopedContext.Updateable(UpdateObjs);
|
return ScopedContext.Updateable(UpdateObjs);
|
||||||
}
|
}
|
||||||
|
public SqlSguarTransaction UseTran()
|
||||||
|
{
|
||||||
|
return ScopedContext.UseTran();
|
||||||
|
}
|
||||||
public DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack = null)
|
public DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack = null)
|
||||||
{
|
{
|
||||||
return ScopedContext.UseTran(action,errorCallBack);
|
return ScopedContext.UseTran(action,errorCallBack);
|
||||||
|
Reference in New Issue
Block a user