From 7d4cd8ea9fbdb03e2879f84489bef4eb46f8ad4f Mon Sep 17 00:00:00 2001 From: zgcwkj Date: Mon, 12 Sep 2022 01:12:27 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=BA=20=E4=BC=98=E5=8C=96=E5=8F=8D?= =?UTF-8?q?=E5=B0=84=E5=8A=A0=E8=BD=BD=E6=A8=A1=E5=9E=8B=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zgcwkj.Util/Data/DataBase/DbCommon.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/zgcwkj.Util/Data/DataBase/DbCommon.cs b/zgcwkj.Util/Data/DataBase/DbCommon.cs index 8bbb845..583d560 100644 --- a/zgcwkj.Util/Data/DataBase/DbCommon.cs +++ b/zgcwkj.Util/Data/DataBase/DbCommon.cs @@ -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()?.Name)); + var entityAssemblyType = entityAssembly.GetTypes(); + var typesToRegister = entityAssemblyType + .Where(p => p.Namespace != null)//排除没有 命名空间 + .Where(p => p.GetCustomAttribute()?.Name != null)//排除没有 TableName + .Where(p => p.GetCustomAttribute() == null);//排除标记 NotMapped foreach (var type in typesToRegister) { dynamic configurationInstance = Activator.CreateInstance(type);