From 859d4cc78a36349e2ebd5486306fd5d4251f9d9b Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 10 Apr 2023 15:42:22 +0800 Subject: [PATCH] Update CodeFirst --- .../Abstract/CodeFirstProvider/CodeFirstProvider.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs index 57080b95e..4a718b03e 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs @@ -48,6 +48,17 @@ namespace SqlSugar public virtual void InitTables(Type entityType) { + var splitTableAttribute = entityType.GetCustomAttribute(); + if (splitTableAttribute != null) + { + var mappingInfo=this.Context.MappingTables.FirstOrDefault(it => it.EntityName == entityType.Name); + if (mappingInfo == null) + { + this.Context.CodeFirst.SplitTables().InitTables(entityType); + this.Context.MappingTables.RemoveAll(it=>it.EntityName==entityType.Name); + return; + } + } //Prevent concurrent requests if used in your program lock (CodeFirstProvider.LockObject) {