namespace Admin.NET.Core;
///
/// SqlSugar仓储类
///
///
public class SqlSugarRepository : SimpleClient where T : class, new()
{
protected ITenant iTenant = null; // 多租户事务
public SqlSugarRepository(ISqlSugarClient context = null) : base(context)
{
iTenant = App.GetRequiredService().AsTenant();
// 根据租户业务实体是否切库
if (typeof(T).IsDefined(typeof(TenantBusinessAttribute), false))
{
var tenantId = App.GetRequiredService().TenantId; // 根据租户Id切库
base.Context = SqlSugarSetup.InitTenantConnection(iTenant, tenantId);
}
else
{
base.Context = iTenant.GetConnectionScopeWithAttr();
}
}
}