forked from anjoy8/Blog.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntityUtility.cs
More file actions
53 lines (46 loc) · 1.57 KB
/
EntityUtility.cs
File metadata and controls
53 lines (46 loc) · 1.57 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
49
50
51
52
53
using Blog.Core.Common.Extensions;
using Blog.Core.Model;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
namespace Blog.Core.Common.DB;
public class EntityUtility
{
private static readonly Lazy<Dictionary<string, List<Type>>> _tenantEntitys = new(() =>
{
Dictionary<string, List<Type>> dic = new Dictionary<string, List<Type>>();
var assembly = Assembly.Load("Blog.Core.Model");
//扫描 实体
foreach (var type in assembly.GetTypes().Where(s => s.IsClass && !s.IsAbstract))
{
var tenant = type.GetCustomAttribute<TenantAttribute>();
if (tenant != null)
{
dic.TryAdd(tenant.configId.ToString(), type);
continue;
}
if (type.IsSubclassOf(typeof(RootEntityTkey<>)))
{
dic.TryAdd(MainDb.CurrentDbConnId, type);
continue;
}
var table = type.GetCustomAttribute<SugarTable>();
if (table != null)
{
dic.TryAdd(MainDb.CurrentDbConnId, type);
continue;
}
Debug.Assert(type.Namespace != null, "type.Namespace != null");
if (type.Namespace.StartsWith("Blog.Core.Model.Models"))
{
dic.TryAdd(MainDb.CurrentDbConnId, type);
continue;
}
}
return dic;
});
public static Dictionary<string, List<Type>> TenantEntitys => _tenantEntitys.Value;
}