From 9345ef7a12bf53c761224774d846752b8a6f4dd1 Mon Sep 17 00:00:00 2001 From: sunkaixuna <610262374@qq.com> Date: Sun, 7 Nov 2021 16:36:07 +0800 Subject: [PATCH] Multi-tenant performance optimization --- Src/Asp.Net/SqlSugar/SqlSugarClient.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Src/Asp.Net/SqlSugar/SqlSugarClient.cs b/Src/Asp.Net/SqlSugar/SqlSugarClient.cs index 58863ef59..3a1b24452 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.Net/SqlSugar/SqlSugarClient.cs @@ -25,6 +25,7 @@ namespace SqlSugar private IgnoreColumnList _IgnoreInsertColumns; internal Guid? AsyncId { get; set; } internal bool? IsSingleInstance { get; set; } + internal List GetConnectionConfigIds = new List(); #endregion @@ -625,6 +626,7 @@ namespace SqlSugar { db.Context.CurrentConnectionConfig.AopEvents = new AopEvents(); } + this.GetConnectionConfigIds.Add(configId+""); return db.Context; } public bool IsAnyConnection(dynamic configId) @@ -665,7 +667,17 @@ namespace SqlSugar public void BeginTran() { _IsAllTran = true; - AllClientEach(it => it.Ado.BeginTran()); + AllClientEach(it => + { + if (this.GetConnectionConfigIds.Any()&&this.GetConnectionConfigIds.Contains(it.CurrentConnectionConfig.ConfigId)) + { + it.Ado.BeginTran(); + } + else + { + it.Ado.BeginTran(); + } + }); } public void CommitTran() {