From 39d624442fcaf94e4adfdfade940d0177d6dc527 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 9 Apr 2022 12:15:28 +0800 Subject: [PATCH] Update core --- Src/Asp.NetCore2/SqlSugar/Interface/ITenant.cs | 1 + Src/Asp.NetCore2/SqlSugar/SqlSugarClient.cs | 8 ++++++++ Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs | 4 ++++ Src/Asp.NetCore2/SqlSugar/Utilities/Check.cs | 9 +++++++++ 4 files changed, 22 insertions(+) diff --git a/Src/Asp.NetCore2/SqlSugar/Interface/ITenant.cs b/Src/Asp.NetCore2/SqlSugar/Interface/ITenant.cs index dc861a27e..33c13967b 100644 --- a/Src/Asp.NetCore2/SqlSugar/Interface/ITenant.cs +++ b/Src/Asp.NetCore2/SqlSugar/Interface/ITenant.cs @@ -21,6 +21,7 @@ namespace SqlSugar Task> UseTranAsync(Func> action, Action errorCallBack = null); void AddConnection(ConnectionConfig connection); SqlSugarProvider GetConnection(dynamic configId); + SqlSugarProvider GetConnectionWithAttr(); bool IsAnyConnection(dynamic configId); void Close(); diff --git a/Src/Asp.NetCore2/SqlSugar/SqlSugarClient.cs b/Src/Asp.NetCore2/SqlSugar/SqlSugarClient.cs index 9fcaa0e5c..177ac9be4 100644 --- a/Src/Asp.NetCore2/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.NetCore2/SqlSugar/SqlSugarClient.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Dynamic; using System.Linq; using System.Linq.Expressions; +using System.Reflection; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -633,6 +634,13 @@ namespace SqlSugar }); } } + public SqlSugarProvider GetConnectionWithAttr() + { + var attr = typeof(T).GetCustomAttribute(); + Check.ExceptionEasy(attr==null,"not TenantAttribute", "不存在特性 TenantAttribute"); + var configId = attr.configId; + return this.GetConnection(configId); + } public SqlSugarProvider GetConnection(dynamic configId) { InitTenant(); diff --git a/Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs b/Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs index 653de9896..cfdba2629 100644 --- a/Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs +++ b/Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs @@ -158,6 +158,10 @@ namespace SqlSugar { return ScopedContext.GetConnection(configId); } + public SqlSugarProvider GetConnectionWithAttr() + { + return ScopedContext.GetConnectionWithAttr(); + } public DateTime GetDate() { diff --git a/Src/Asp.NetCore2/SqlSugar/Utilities/Check.cs b/Src/Asp.NetCore2/SqlSugar/Utilities/Check.cs index 6aab95909..4170bd886 100644 --- a/Src/Asp.NetCore2/SqlSugar/Utilities/Check.cs +++ b/Src/Asp.NetCore2/SqlSugar/Utilities/Check.cs @@ -29,5 +29,14 @@ namespace SqlSugar if (isException) throw new SqlSugarException(string.Format(message, args)); } + public static void ExceptionEasy(string enMessage, string cnMessage) + { + throw new SqlSugarException(ErrorMessage.GetThrowMessage(enMessage, cnMessage)); + } + public static void ExceptionEasy(bool isException, string enMessage, string cnMessage) + { + if (isException) + throw new SqlSugarException(ErrorMessage.GetThrowMessage(enMessage, cnMessage)); + } } }