Update demo

This commit is contained in:
sunkaixuan 2022-04-09 12:13:13 +08:00
parent 06d4f13599
commit e0f15ec15d
3 changed files with 7 additions and 3 deletions

View File

@ -50,8 +50,7 @@ namespace OrmTest
{ {
if (context == null) if (context == null)
{ {
var configId = typeof(T).GetCustomAttribute<TenantAttribute>().configId; Context = db.GetConnectionWithAttr<T>();
Context = db.GetConnection(configId);
Context.CodeFirst.InitTables<T>(); Context.CodeFirst.InitTables<T>();
} }
} }

View File

@ -637,7 +637,7 @@ namespace SqlSugar
public SqlSugarProvider GetConnectionWithAttr<T>() public SqlSugarProvider GetConnectionWithAttr<T>()
{ {
var attr = typeof(T).GetCustomAttribute<TenantAttribute>(); var attr = typeof(T).GetCustomAttribute<TenantAttribute>();
Check.ExceptionEasy("not TenantAttribute", "不存在特性 TenantAttribute"); Check.ExceptionEasy(attr==null,"not TenantAttribute", "不存在特性 TenantAttribute");
var configId = attr.configId; var configId = attr.configId;
return this.GetConnection(configId); return this.GetConnection(configId);
} }

View File

@ -33,5 +33,10 @@ namespace SqlSugar
{ {
throw new SqlSugarException(ErrorMessage.GetThrowMessage(enMessage, 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));
}
} }
} }