diff --git a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs index 5284b7fa1..29ccf4175 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs @@ -22,7 +22,9 @@ namespace SqlSugar } public virtual void InitTables(Type entityType) { + this.Context.RewritableMethods.RemoveCacheAll(); + this.Context.InitMppingInfo(entityType); if (!this.Context.DbMaintenance.IsAnySystemTablePermissions()) { Check.Exception(true, "Dbfirst and Codefirst requires system table permissions"); diff --git a/Src/Asp.Net/SqlSugar/SqlSugarAccessory.cs b/Src/Asp.Net/SqlSugar/SqlSugarAccessory.cs index 86e24178a..43bd56900 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugarAccessory.cs +++ b/Src/Asp.Net/SqlSugar/SqlSugarAccessory.cs @@ -68,7 +68,11 @@ namespace SqlSugar } protected void InitMppingInfo() { - string cacheKey = "Context.InitAttributeMappingTables" + typeof(T).FullName; + InitMppingInfo(typeof(T)); + } + public void InitMppingInfo(Type type) + { + string cacheKey = "Context.InitAttributeMappingTables" + type.FullName; var entityInfo = this.Context.RewritableMethods.GetCacheInstance().Func(cacheKey, (cm, key) => { @@ -77,7 +81,7 @@ namespace SqlSugar }, (cm, key) => { - var reval = this.Context.EntityProvider.GetEntityInfo(); + var reval = this.Context.EntityProvider.GetEntityInfo(type); return reval; }); InitMppingInfo(entityInfo); diff --git a/Src/Asp.Net/SqlSugar/SqlSugarClient.cs b/Src/Asp.Net/SqlSugar/SqlSugarClient.cs index 1c17a7891..dd114c65e 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.Net/SqlSugar/SqlSugarClient.cs @@ -263,6 +263,7 @@ namespace SqlSugar } public virtual IInsertable Insertable(Dictionary columnDictionary) where T : class, new() { + InitMppingInfo(); Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Insertable.columnDictionary can't be null"); var insertObject = this.RewritableMethods.DeserializeObject(this.RewritableMethods.SerializeObject(columnDictionary)); var columns = columnDictionary.Select(it => it.Key).ToList(); @@ -270,6 +271,7 @@ namespace SqlSugar } public virtual IInsertable Insertable(dynamic insertDynamicObject) where T : class, new() { + InitMppingInfo(); if (insertDynamicObject is T) { return this.Insertable((T)insertDynamicObject); @@ -293,26 +295,32 @@ namespace SqlSugar } public virtual IDeleteable Deleteable(Expression> expression) where T : class, new() { + InitMppingInfo(); return this.Deleteable().Where(expression); } public virtual IDeleteable Deleteable(dynamic primaryKeyValue) where T : class, new() { + InitMppingInfo(); return this.Deleteable().In(primaryKeyValue); } public virtual IDeleteable Deleteable(dynamic[] primaryKeyValues) where T : class, new() { + InitMppingInfo(); return this.Deleteable().In(primaryKeyValues); } public virtual IDeleteable Deleteable(List pkValue) where T : class, new() { + InitMppingInfo(); return this.Deleteable().In(pkValue); } public virtual IDeleteable Deleteable(T deleteObj) where T : class, new() { + InitMppingInfo(); return this.Deleteable().Where(deleteObj); } public virtual IDeleteable Deleteable(List deleteObjs) where T : class, new() { + InitMppingInfo(); return this.Deleteable().Where(deleteObjs); } #endregion @@ -339,6 +347,7 @@ namespace SqlSugar } public virtual IUpdateable Updateable(Dictionary columnDictionary) where T : class, new() { + InitMppingInfo(); Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Updateable.columnDictionary can't be null"); var updateObject = this.RewritableMethods.DeserializeObject(this.RewritableMethods.SerializeObject(columnDictionary)); var columns = columnDictionary.Select(it => it.Key).ToList(); @@ -346,6 +355,7 @@ namespace SqlSugar } public virtual IUpdateable Updateable(dynamic updateDynamicObject) where T : class, new() { + InitMppingInfo(); if (updateDynamicObject is T) { return this.Updateable((T)updateDynamicObject);