mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-17 19:37:34 +08:00
Update support pure Dictionary
This commit is contained in:
parent
c4cdb31938
commit
edc8a60c40
@ -38,6 +38,11 @@ namespace OrmTest.Demo
|
|||||||
//Use Lock
|
//Use Lock
|
||||||
var t6 = db.Updateable(updateObj).With(SqlWith.UpdLock).ExecuteCommand();
|
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>
|
//update List<T>
|
||||||
//var t7 = db.Updateable(updateObjs).ExecuteCommand();
|
//var t7 = db.Updateable(updateObjs).ExecuteCommand();
|
||||||
|
|
||||||
|
@ -226,6 +226,40 @@ namespace SqlSugar
|
|||||||
foreach (var item in UpdateObjs)
|
foreach (var item in UpdateObjs)
|
||||||
{
|
{
|
||||||
List<DbColumnInfo> updateItem = new List<DbColumnInfo>();
|
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)
|
foreach (var column in EntityInfo.Columns)
|
||||||
{
|
{
|
||||||
var columnInfo = new DbColumnInfo()
|
var columnInfo = new DbColumnInfo()
|
||||||
@ -243,9 +277,8 @@ namespace SqlSugar
|
|||||||
updateItem.Add(columnInfo);
|
updateItem.Add(columnInfo);
|
||||||
}
|
}
|
||||||
this.UpdateBuilder.DbColumnInfoList.AddRange(updateItem);
|
this.UpdateBuilder.DbColumnInfoList.AddRange(updateItem);
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PreToSql()
|
private void PreToSql()
|
||||||
{
|
{
|
||||||
UpdateBuilder.PrimaryKeys = GetPrimaryKeys();
|
UpdateBuilder.PrimaryKeys = GetPrimaryKeys();
|
||||||
|
Loading…
Reference in New Issue
Block a user