Update support pure Dictionary

This commit is contained in:
sunkaixuan 2018-04-08 15:15:33 +08:00
parent c4cdb31938
commit edc8a60c40
2 changed files with 53 additions and 15 deletions

View File

@ -38,6 +38,11 @@ namespace OrmTest.Demo
//Use Lock
var t6 = db.Updateable(updateObj).With(SqlWith.UpdLock).ExecuteCommand();
var dt = new Dictionary<string,object>();
dt.Add("id", 1);
dt.Add("name", "1");
var t66 = db.Updateable(dt).AS("student").With(SqlWith.UpdLock).ExecuteCommand();
//update List<T>
//var t7 = db.Updateable(updateObjs).ExecuteCommand();

View File

@ -226,6 +226,40 @@ namespace SqlSugar
foreach (var item in UpdateObjs)
{
List<DbColumnInfo> updateItem = new List<DbColumnInfo>();
var isDic = item is Dictionary<string,object>;
if (isDic)
{
SetUpdateItemByDic(i, item, updateItem);
}
else
{
SetUpdateItemByEntity(i, item, updateItem);
}
++i;
}
}
private void SetUpdateItemByDic(int i, T item, List<DbColumnInfo> updateItem)
{
foreach (var column in item as Dictionary<string,object>)
{
var columnInfo = new DbColumnInfo()
{
Value = column.Value,
DbColumnName =column.Key,
PropertyName = column.Key,
PropertyType = UtilMethods.GetUnderType(column.Value.GetType()),
TableId = i
};
if (columnInfo.PropertyType.IsEnum())
{
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
}
updateItem.Add(columnInfo);
}
this.UpdateBuilder.DbColumnInfoList.AddRange(updateItem);
}
private void SetUpdateItemByEntity(int i, T item, List<DbColumnInfo> updateItem)
{
foreach (var column in EntityInfo.Columns)
{
var columnInfo = new DbColumnInfo()
@ -243,9 +277,8 @@ namespace SqlSugar
updateItem.Add(columnInfo);
}
this.UpdateBuilder.DbColumnInfoList.AddRange(updateItem);
++i;
}
}
private void PreToSql()
{
UpdateBuilder.PrimaryKeys = GetPrimaryKeys();