@@ -14,11 +14,12 @@ namespace OSharp.Entity;
1414/// </summary>
1515public class EntityManager : IEntityManager
1616{
17- private readonly ConcurrentDictionary < Type , IEntityRegister [ ] > _entityRegistersDict
18- = new ConcurrentDictionary < Type , IEntityRegister [ ] > ( ) ;
17+ private readonly ConcurrentDictionary < Type , IEntityRegister [ ] > _entityRegistersDict = new ( ) ;
1918 private readonly ILogger _logger ;
2019 private bool _initialized ;
2120
21+ public static bool IncludeSpecialTable = true ;
22+
2223 /// <summary>
2324 /// 初始化一个<see cref="EntityManager"/>类型的新实例
2425 /// </summary>
@@ -33,7 +34,7 @@ public EntityManager(IServiceProvider provider)
3334 public virtual void Initialize ( )
3435 {
3536 var dict = _entityRegistersDict ;
36- Type [ ] types = AssemblyManager . FindTypesByBase < IEntityRegister > ( ) ;
37+ Type [ ] types = AssemblyManager . FindTypesByBase < IEntityRegister > ( ) . Where ( m => ! m . IsNestedPrivate ) . ToArray ( ) ;
3738 if ( types . Length == 0 || _initialized )
3839 {
3940 _logger . LogDebug ( "数据库上下文实体已初始化,跳过" ) ;
@@ -48,14 +49,14 @@ public virtual void Initialize()
4849 foreach ( IGrouping < Type , IEntityRegister > group in groups )
4950 {
5051 key = group . Key ?? typeof ( DefaultDbContext ) ;
51- List < IEntityRegister > list = dict . ContainsKey ( key ) ? dict [ key ] . ToList ( ) : new List < IEntityRegister > ( ) ;
52+ List < IEntityRegister > list = dict . TryGetValue ( key , out var value ) ? value . ToList ( ) : new List < IEntityRegister > ( ) ;
5253 list . AddRange ( group ) ;
5354 dict [ key ] = list . ToArray ( ) ;
5455 }
5556
5657 //添加框架的一些默认实体的实体映射信息(如果不存在)
5758 key = typeof ( DefaultDbContext ) ;
58- if ( dict . ContainsKey ( key ) )
59+ if ( dict . ContainsKey ( key ) && IncludeSpecialTable )
5960 {
6061 List < IEntityRegister > list = dict [ key ] . ToList ( ) ;
6162 list . AddIfNotExist ( new EntityInfoConfiguration ( ) , m => m . EntityType . IsBaseOn < IEntityInfo > ( ) ) ;
@@ -87,7 +88,7 @@ public virtual IEntityRegister[] GetEntityRegisters(Type dbContextType)
8788 {
8889 throw new OsharpException ( "数据访问模块未初始化,请确认数据上下文配置节点 OSharp:DbContexts 与要使用的数据库类型是否匹配" ) ;
8990 }
90- return _entityRegistersDict . ContainsKey ( dbContextType ) ? _entityRegistersDict [ dbContextType ] : Array . Empty < IEntityRegister > ( ) ;
91+ return _entityRegistersDict . TryGetValue ( dbContextType , out var value ) ? value : Array . Empty < IEntityRegister > ( ) ;
9192 }
9293
9394 /// <summary>
0 commit comments