mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-03 12:18:00 +08:00
Code First Bug
This commit is contained in:
parent
a23c475aea
commit
f40addabcd
@ -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");
|
||||
|
@ -68,7 +68,11 @@ namespace SqlSugar
|
||||
}
|
||||
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,
|
||||
(cm, key) =>
|
||||
{
|
||||
@ -77,7 +81,7 @@ namespace SqlSugar
|
||||
},
|
||||
(cm, key) =>
|
||||
{
|
||||
var reval = this.Context.EntityProvider.GetEntityInfo<T>();
|
||||
var reval = this.Context.EntityProvider.GetEntityInfo(type);
|
||||
return reval;
|
||||
});
|
||||
InitMppingInfo(entityInfo);
|
||||
|
@ -263,6 +263,7 @@ namespace SqlSugar
|
||||
}
|
||||
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");
|
||||
var insertObject = this.RewritableMethods.DeserializeObject<T>(this.RewritableMethods.SerializeObject(columnDictionary));
|
||||
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()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
if (insertDynamicObject is T)
|
||||
{
|
||||
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()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().Where(expression);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(dynamic primaryKeyValue) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().In(primaryKeyValue);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(dynamic[] primaryKeyValues) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().In(primaryKeyValues);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(List<dynamic> pkValue) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().In(pkValue);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(T deleteObj) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().Where(deleteObj);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(List<T> deleteObjs) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().Where(deleteObjs);
|
||||
}
|
||||
#endregion
|
||||
@ -339,6 +347,7 @@ namespace SqlSugar
|
||||
}
|
||||
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");
|
||||
var updateObject = this.RewritableMethods.DeserializeObject<T>(this.RewritableMethods.SerializeObject(columnDictionary));
|
||||
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()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
if (updateDynamicObject is T)
|
||||
{
|
||||
return this.Updateable((T)updateDynamicObject);
|
||||
|
Loading…
Reference in New Issue
Block a user