forked from anjoy8/Blog.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepositorySetting.cs
More file actions
48 lines (41 loc) · 1.42 KB
/
RepositorySetting.cs
File metadata and controls
48 lines (41 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using Blog.Core.Model.Models.RootTkey;
using Blog.Core.Model.Models.RootTkey.Interface;
using Blog.Core.Model.Tenants;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Blog.Core.Common.DB;
public class RepositorySetting
{
private static readonly Lazy<IEnumerable<Type>> AllEntitys = new(() =>
{
return typeof(BaseEntity).Assembly
.GetTypes()
.Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(BaseEntity)))
.Where(it => it.FullName != null && it.FullName.StartsWith("Blog.Core.Model.Models"));
});
public static IEnumerable<Type> Entitys => AllEntitys.Value;
/// <summary>
/// 配置实体软删除过滤器<br/>
/// 统一过滤 软删除 无需自己写条件
/// </summary>
public static void SetDeletedEntityFilter(SqlSugarScopeProvider db)
{
db.QueryFilter.AddTableFilter<IDeleteFilter>(it => it.IsDeleted == false);
}
/// <summary>
/// 配置租户
/// </summary>
public static void SetTenantEntityFilter(SqlSugarScopeProvider db)
{
if (App.User is not { ID: > 0, TenantId: > 0 })
{
return;
}
//多租户 单表
db.QueryFilter.AddTableFilter<ITenantEntity>(it => it.TenantId == App.User.TenantId || it.TenantId == 0);
//多租户 多表
db.SetTenantTable(App.User.TenantId.ToString());
}
}