mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 14:04:44 +08:00
Update support pure Dictionary
This commit is contained in:
parent
c4cdb31938
commit
edc8a60c40
@ -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();
|
||||
|
||||
|
@ -226,26 +226,59 @@ namespace SqlSugar
|
||||
foreach (var item in UpdateObjs)
|
||||
{
|
||||
List<DbColumnInfo> updateItem = new List<DbColumnInfo>();
|
||||
foreach (var column in EntityInfo.Columns)
|
||||
var isDic = item is Dictionary<string,object>;
|
||||
if (isDic)
|
||||
{
|
||||
var columnInfo = new DbColumnInfo()
|
||||
{
|
||||
Value = column.PropertyInfo.GetValue(item, null),
|
||||
DbColumnName = GetDbColumnName(column.PropertyName),
|
||||
PropertyName = column.PropertyName,
|
||||
PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
|
||||
TableId = i
|
||||
};
|
||||
if (columnInfo.PropertyType.IsEnum())
|
||||
{
|
||||
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
|
||||
}
|
||||
updateItem.Add(columnInfo);
|
||||
SetUpdateItemByDic(i, item, updateItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetUpdateItemByEntity(i, item, updateItem);
|
||||
}
|
||||
this.UpdateBuilder.DbColumnInfoList.AddRange(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()
|
||||
{
|
||||
Value = column.PropertyInfo.GetValue(item, null),
|
||||
DbColumnName = GetDbColumnName(column.PropertyName),
|
||||
PropertyName = column.PropertyName,
|
||||
PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
|
||||
TableId = i
|
||||
};
|
||||
if (columnInfo.PropertyType.IsEnum())
|
||||
{
|
||||
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
|
||||
}
|
||||
updateItem.Add(columnInfo);
|
||||
}
|
||||
this.UpdateBuilder.DbColumnInfoList.AddRange(updateItem);
|
||||
}
|
||||
|
||||
private void PreToSql()
|
||||
{
|
||||
UpdateBuilder.PrimaryKeys = GetPrimaryKeys();
|
||||
|
Loading…
Reference in New Issue
Block a user