mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-18 17:48:11 +08:00
Insert support pure Dictionary
This commit is contained in:
@@ -59,6 +59,11 @@ namespace OrmTest.Demo
|
|||||||
|
|
||||||
var t12 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").ExecuteReturnIdentityAsync();
|
var t12 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").ExecuteReturnIdentityAsync();
|
||||||
t12.Wait();
|
t12.Wait();
|
||||||
|
|
||||||
|
|
||||||
|
var dt = new Dictionary<string, object>();
|
||||||
|
dt.Add("name", "1");
|
||||||
|
var t66 = db.Insertable(dt).AS("student").ExecuteReturnEntity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -264,27 +264,58 @@ namespace SqlSugar
|
|||||||
foreach (var item in InsertObjs)
|
foreach (var item in InsertObjs)
|
||||||
{
|
{
|
||||||
List<DbColumnInfo> insertItem = new List<DbColumnInfo>();
|
List<DbColumnInfo> insertItem = new List<DbColumnInfo>();
|
||||||
foreach (var column in EntityInfo.Columns)
|
if (item is Dictionary<string, object>)
|
||||||
{
|
{
|
||||||
if (column.IsIgnore || column.IsOnlyIgnoreInsert) continue;
|
SetInsertItemByDic(i, item, insertItem);
|
||||||
var columnInfo = new DbColumnInfo()
|
}
|
||||||
{
|
else
|
||||||
Value = column.PropertyInfo.GetValue(item, null),
|
{
|
||||||
DbColumnName = GetDbColumnName(column.PropertyName),
|
SetInsertItemByEntity(i, item, insertItem);
|
||||||
PropertyName = column.PropertyName,
|
|
||||||
PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
|
|
||||||
TableId = i
|
|
||||||
};
|
|
||||||
if (columnInfo.PropertyType.IsEnum())
|
|
||||||
{
|
|
||||||
columnInfo.Value = Convert.ToInt64(columnInfo.Value);
|
|
||||||
}
|
|
||||||
insertItem.Add(columnInfo);
|
|
||||||
}
|
}
|
||||||
this.InsertBuilder.DbColumnInfoList.AddRange(insertItem);
|
this.InsertBuilder.DbColumnInfoList.AddRange(insertItem);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void SetInsertItemByDic(int i, T item, List<DbColumnInfo> insertItem)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
insertItem.Add(columnInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void SetInsertItemByEntity(int i, T item, List<DbColumnInfo> insertItem)
|
||||||
|
{
|
||||||
|
foreach (var column in EntityInfo.Columns)
|
||||||
|
{
|
||||||
|
if (column.IsIgnore || column.IsOnlyIgnoreInsert) continue;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
insertItem.Add(columnInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private string GetDbColumnName(string propertyName)
|
private string GetDbColumnName(string propertyName)
|
||||||
{
|
{
|
||||||
if (!IsMappingColumns)
|
if (!IsMappingColumns)
|
||||||
|
Reference in New Issue
Block a user