From 41bc3c53dd6407a66388f8ec1fdac17195ba6c6f Mon Sep 17 00:00:00 2001 From: sunkaixuna <610262374@qq.com> Date: Wed, 1 Sep 2021 00:28:25 +0800 Subject: [PATCH] Add db.UseTran(+0) --- .../SqlSugar/Entities/SqlSguarTransaction.cs | 23 +++++++++++++++++++ Src/Asp.Net/SqlSugar/Interface/ITenant.cs | 1 + Src/Asp.Net/SqlSugar/SqlSugar.csproj | 1 + Src/Asp.Net/SqlSugar/SqlSugarClient.cs | 4 ++++ Src/Asp.Net/SqlSugar/SqlSugarScope.cs | 5 +++- 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 Src/Asp.Net/SqlSugar/Entities/SqlSguarTransaction.cs diff --git a/Src/Asp.Net/SqlSugar/Entities/SqlSguarTransaction.cs b/Src/Asp.Net/SqlSugar/Entities/SqlSguarTransaction.cs new file mode 100644 index 000000000..f7a48fc69 --- /dev/null +++ b/Src/Asp.Net/SqlSugar/Entities/SqlSguarTransaction.cs @@ -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(); + } + } +} diff --git a/Src/Asp.Net/SqlSugar/Interface/ITenant.cs b/Src/Asp.Net/SqlSugar/Interface/ITenant.cs index d94a8a2f1..c4ade4aaf 100644 --- a/Src/Asp.Net/SqlSugar/Interface/ITenant.cs +++ b/Src/Asp.Net/SqlSugar/Interface/ITenant.cs @@ -13,6 +13,7 @@ namespace SqlSugar void RollbackTran(); void ChangeDatabase(dynamic configId); void ChangeDatabase(Func changeExpression); + SqlSguarTransaction UseTran(); DbResult UseTran(Action action, Action errorCallBack = null); Task> UseTranAsync(Func action, Action errorCallBack = null); DbResult UseTran(Func action, Action errorCallBack = null); diff --git a/Src/Asp.Net/SqlSugar/SqlSugar.csproj b/Src/Asp.Net/SqlSugar/SqlSugar.csproj index 1ce021eaa..3b4653e46 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugar.csproj +++ b/Src/Asp.Net/SqlSugar/SqlSugar.csproj @@ -88,6 +88,7 @@ + diff --git a/Src/Asp.Net/SqlSugar/SqlSugarClient.cs b/Src/Asp.Net/SqlSugar/SqlSugarClient.cs index 378314526..7b94531ab 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.Net/SqlSugar/SqlSugarClient.cs @@ -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"); diff --git a/Src/Asp.Net/SqlSugar/SqlSugarScope.cs b/Src/Asp.Net/SqlSugar/SqlSugarScope.cs index 5c177d36c..92c6248cc 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugarScope.cs +++ b/Src/Asp.Net/SqlSugar/SqlSugarScope.cs @@ -651,7 +651,10 @@ namespace SqlSugar { return ScopedContext.Updateable(UpdateObjs); } - + public SqlSguarTransaction UseTran() + { + return ScopedContext.UseTran(); + } public DbResult UseTran(Action action, Action errorCallBack = null) { return ScopedContext.UseTran(action,errorCallBack);