using EntrustSettle.Common.Extensions; using EntrustSettle.Model; using SqlSugar; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; namespace EntrustSettle.Common.DB; public class EntityUtility { private static readonly Lazy>> _tenantEntitys = new(() => { Dictionary> dic = new Dictionary>(); var assembly = Assembly.Load("EntrustSettle.Model"); //扫描 实体 foreach (var type in assembly.GetTypes().Where(s => s.IsClass && !s.IsAbstract)) { var tenant = type.GetCustomAttribute(); 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(); if (table != null) { dic.TryAdd(MainDb.CurrentDbConnId, type); continue; } Debug.Assert(type.Namespace != null, "type.Namespace != null"); if (type.Namespace.StartsWith("EntrustSettle.Model.Models")) { dic.TryAdd(MainDb.CurrentDbConnId, type); continue; } } return dic; }); public static Dictionary> TenantEntitys => _tenantEntitys.Value; }