Browse Source

Code First Bug

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
f40addabcd
  1. 2
      Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs
  2. 8
      Src/Asp.Net/SqlSugar/SqlSugarAccessory.cs
  3. 10
      Src/Asp.Net/SqlSugar/SqlSugarClient.cs

2
Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs

@ -22,7 +22,9 @@ namespace SqlSugar
} }
public virtual void InitTables(Type entityType) public virtual void InitTables(Type entityType)
{ {
this.Context.RewritableMethods.RemoveCacheAll(); this.Context.RewritableMethods.RemoveCacheAll();
this.Context.InitMppingInfo(entityType);
if (!this.Context.DbMaintenance.IsAnySystemTablePermissions()) if (!this.Context.DbMaintenance.IsAnySystemTablePermissions())
{ {
Check.Exception(true, "Dbfirst and Codefirst requires system table permissions"); Check.Exception(true, "Dbfirst and Codefirst requires system table permissions");

8
Src/Asp.Net/SqlSugar/SqlSugarAccessory.cs

@ -68,7 +68,11 @@ namespace SqlSugar
} }
protected void InitMppingInfo<T>() protected void InitMppingInfo<T>()
{ {
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<EntityInfo>().Func(cacheKey, var entityInfo = this.Context.RewritableMethods.GetCacheInstance<EntityInfo>().Func(cacheKey,
(cm, key) => (cm, key) =>
{ {
@ -77,7 +81,7 @@ namespace SqlSugar
}, },
(cm, key) => (cm, key) =>
{ {
var reval = this.Context.EntityProvider.GetEntityInfo<T>(); var reval = this.Context.EntityProvider.GetEntityInfo(type);
return reval; return reval;
}); });
InitMppingInfo(entityInfo); InitMppingInfo(entityInfo);

10
Src/Asp.Net/SqlSugar/SqlSugarClient.cs

@ -263,6 +263,7 @@ namespace SqlSugar
} }
public virtual IInsertable<T> Insertable<T>(Dictionary<string, object> columnDictionary) where T : class, new() public virtual IInsertable<T> Insertable<T>(Dictionary<string, object> columnDictionary) where T : class, new()
{ {
InitMppingInfo<T>();
Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Insertable.columnDictionary can't be null"); Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Insertable.columnDictionary can't be null");
var insertObject = this.RewritableMethods.DeserializeObject<T>(this.RewritableMethods.SerializeObject(columnDictionary)); var insertObject = this.RewritableMethods.DeserializeObject<T>(this.RewritableMethods.SerializeObject(columnDictionary));
var columns = columnDictionary.Select(it => it.Key).ToList(); var columns = columnDictionary.Select(it => it.Key).ToList();
@ -270,6 +271,7 @@ namespace SqlSugar
} }
public virtual IInsertable<T> Insertable<T>(dynamic insertDynamicObject) where T : class, new() public virtual IInsertable<T> Insertable<T>(dynamic insertDynamicObject) where T : class, new()
{ {
InitMppingInfo<T>();
if (insertDynamicObject is T) if (insertDynamicObject is T)
{ {
return this.Insertable((T)insertDynamicObject); return this.Insertable((T)insertDynamicObject);
@ -293,26 +295,32 @@ namespace SqlSugar
} }
public virtual IDeleteable<T> Deleteable<T>(Expression<Func<T, bool>> expression) where T : class, new() public virtual IDeleteable<T> Deleteable<T>(Expression<Func<T, bool>> expression) where T : class, new()
{ {
InitMppingInfo<T>();
return this.Deleteable<T>().Where(expression); return this.Deleteable<T>().Where(expression);
} }
public virtual IDeleteable<T> Deleteable<T>(dynamic primaryKeyValue) where T : class, new() public virtual IDeleteable<T> Deleteable<T>(dynamic primaryKeyValue) where T : class, new()
{ {
InitMppingInfo<T>();
return this.Deleteable<T>().In(primaryKeyValue); return this.Deleteable<T>().In(primaryKeyValue);
} }
public virtual IDeleteable<T> Deleteable<T>(dynamic[] primaryKeyValues) where T : class, new() public virtual IDeleteable<T> Deleteable<T>(dynamic[] primaryKeyValues) where T : class, new()
{ {
InitMppingInfo<T>();
return this.Deleteable<T>().In(primaryKeyValues); return this.Deleteable<T>().In(primaryKeyValues);
} }
public virtual IDeleteable<T> Deleteable<T>(List<dynamic> pkValue) where T : class, new() public virtual IDeleteable<T> Deleteable<T>(List<dynamic> pkValue) where T : class, new()
{ {
InitMppingInfo<T>();
return this.Deleteable<T>().In(pkValue); return this.Deleteable<T>().In(pkValue);
} }
public virtual IDeleteable<T> Deleteable<T>(T deleteObj) where T : class, new() public virtual IDeleteable<T> Deleteable<T>(T deleteObj) where T : class, new()
{ {
InitMppingInfo<T>();
return this.Deleteable<T>().Where(deleteObj); return this.Deleteable<T>().Where(deleteObj);
} }
public virtual IDeleteable<T> Deleteable<T>(List<T> deleteObjs) where T : class, new() public virtual IDeleteable<T> Deleteable<T>(List<T> deleteObjs) where T : class, new()
{ {
InitMppingInfo<T>();
return this.Deleteable<T>().Where(deleteObjs); return this.Deleteable<T>().Where(deleteObjs);
} }
#endregion #endregion
@ -339,6 +347,7 @@ namespace SqlSugar
} }
public virtual IUpdateable<T> Updateable<T>(Dictionary<string, object> columnDictionary) where T : class, new() public virtual IUpdateable<T> Updateable<T>(Dictionary<string, object> columnDictionary) where T : class, new()
{ {
InitMppingInfo<T>();
Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Updateable.columnDictionary can't be null"); Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Updateable.columnDictionary can't be null");
var updateObject = this.RewritableMethods.DeserializeObject<T>(this.RewritableMethods.SerializeObject(columnDictionary)); var updateObject = this.RewritableMethods.DeserializeObject<T>(this.RewritableMethods.SerializeObject(columnDictionary));
var columns = columnDictionary.Select(it => it.Key).ToList(); var columns = columnDictionary.Select(it => it.Key).ToList();
@ -346,6 +355,7 @@ namespace SqlSugar
} }
public virtual IUpdateable<T> Updateable<T>(dynamic updateDynamicObject) where T : class, new() public virtual IUpdateable<T> Updateable<T>(dynamic updateDynamicObject) where T : class, new()
{ {
InitMppingInfo<T>();
if (updateDynamicObject is T) if (updateDynamicObject is T)
{ {
return this.Updateable((T)updateDynamicObject); return this.Updateable((T)updateDynamicObject);

Loading…
Cancel
Save