From e0f15ec15d6dd62f9f4833a8230a0ff42eaa04ad Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 9 Apr 2022 12:13:13 +0800 Subject: [PATCH] Update demo --- Src/Asp.Net/SqlServerTest/Demo/DemoH_Tenant.cs | 3 +-- Src/Asp.Net/SqlSugar/SqlSugarClient.cs | 2 +- Src/Asp.Net/SqlSugar/Utilities/Check.cs | 5 +++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Src/Asp.Net/SqlServerTest/Demo/DemoH_Tenant.cs b/Src/Asp.Net/SqlServerTest/Demo/DemoH_Tenant.cs index 16fdd3826..f303577ba 100644 --- a/Src/Asp.Net/SqlServerTest/Demo/DemoH_Tenant.cs +++ b/Src/Asp.Net/SqlServerTest/Demo/DemoH_Tenant.cs @@ -50,8 +50,7 @@ namespace OrmTest { if (context == null) { - var configId = typeof(T).GetCustomAttribute().configId; - Context = db.GetConnection(configId); + Context = db.GetConnectionWithAttr(); Context.CodeFirst.InitTables(); } } diff --git a/Src/Asp.Net/SqlSugar/SqlSugarClient.cs b/Src/Asp.Net/SqlSugar/SqlSugarClient.cs index 01f0bf81d..177ac9be4 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.Net/SqlSugar/SqlSugarClient.cs @@ -637,7 +637,7 @@ namespace SqlSugar public SqlSugarProvider GetConnectionWithAttr() { var attr = typeof(T).GetCustomAttribute(); - Check.ExceptionEasy("not TenantAttribute", "不存在特性 TenantAttribute"); + Check.ExceptionEasy(attr==null,"not TenantAttribute", "不存在特性 TenantAttribute"); var configId = attr.configId; return this.GetConnection(configId); } diff --git a/Src/Asp.Net/SqlSugar/Utilities/Check.cs b/Src/Asp.Net/SqlSugar/Utilities/Check.cs index 569b73a00..4170bd886 100644 --- a/Src/Asp.Net/SqlSugar/Utilities/Check.cs +++ b/Src/Asp.Net/SqlSugar/Utilities/Check.cs @@ -33,5 +33,10 @@ namespace SqlSugar { 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)); + } } }