Skip to content

Commit

Permalink
🏺 优化反射加载模型的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zgcwkj committed Sep 11, 2022
1 parent 5eb2f81 commit 7d4cd8e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions zgcwkj.Util/Data/DataBase/DbCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
var fileName = file.Name.Replace(file.Extension, "");
var assemblyName = new AssemblyName(fileName);
var entityAssembly = Assembly.Load(assemblyName);
var typesToRegister = entityAssembly.GetTypes()
.Where(p => !string.IsNullOrEmpty(p.Namespace))
.Where(p => !string.IsNullOrEmpty(p.GetCustomAttribute<TableAttribute>()?.Name));
var entityAssemblyType = entityAssembly.GetTypes();
var typesToRegister = entityAssemblyType
.Where(p => p.Namespace != null)//排除没有 命名空间
.Where(p => p.GetCustomAttribute<TableAttribute>()?.Name != null)//排除没有 TableName
.Where(p => p.GetCustomAttribute<NotMappedAttribute>() == null);//排除标记 NotMapped
foreach (var type in typesToRegister)
{
dynamic configurationInstance = Activator.CreateInstance(type);
Expand Down

0 comments on commit 7d4cd8e

Please sign in to comment.