Browse Source

Update SetChildList

pull/18/head
sunkaixuan 3 years ago
parent
commit
f84abe1ab3
  1. 105
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/MappingFieldsHelper.cs

105
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/MappingFieldsHelper.cs

@ -60,54 +60,7 @@ namespace SqlSugar
if (item != null)
{
//var expable =Expressionable.Create<object>();
foreach (var field in mappingFieldsExpressions)
{
InitMappingFieldsExpression(field);
}
var setList =new List<object>();
var count = mappingFieldsExpressions.Count;
if (count == 1)
{
setList=list.Where(it => GetWhereByIndex(item, mappingFieldsExpressions, it, 0)).ToList();
}
else if (count == 2)
{
setList = list.Where(it =>
GetWhereByIndex(item, mappingFieldsExpressions, it, 0) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 1)
).ToList();
}
else if (count == 3)
{
setList = list.Where(it =>
GetWhereByIndex(item, mappingFieldsExpressions, it, 0) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 1) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 2)
).ToList();
}
else if (count == 4)
{
setList = list.Where(it =>
GetWhereByIndex(item, mappingFieldsExpressions, it, 0) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 1) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 2) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 3)
).ToList();
}
else if (count == 5)
{
setList = list.Where(it =>
GetWhereByIndex(item, mappingFieldsExpressions, it, 0) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 1) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 2) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 3) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 4)
).ToList();
}
else
{
Check.ExceptionEasy("MappingField max value is 5", "MappingField最大数量不能超过5");
}
List<object> setList = GetSetList(item, list, mappingFieldsExpressions);
//navColumnInfo.PropertyInfo.SetValue();
var instance = Activator.CreateInstance(navColumnInfo.PropertyInfo.PropertyType, true);
var ilist = instance as IList;
@ -115,10 +68,64 @@ namespace SqlSugar
{
ilist.Add(value);
}
navColumnInfo.PropertyInfo.SetValue(item,ilist);
navColumnInfo.PropertyInfo.SetValue(item, ilist);
}
}
private List<object> GetSetList(object item, List<object> list, List<MappingFieldsExpression> mappingFieldsExpressions)
{
foreach (var field in mappingFieldsExpressions)
{
InitMappingFieldsExpression(field);
}
var setList = new List<object>();
var count = mappingFieldsExpressions.Count;
if (count == 1)
{
setList = list.Where(it => GetWhereByIndex(item, mappingFieldsExpressions, it, 0)).ToList();
}
else if (count == 2)
{
setList = list.Where(it =>
GetWhereByIndex(item, mappingFieldsExpressions, it, 0) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 1)
).ToList();
}
else if (count == 3)
{
setList = list.Where(it =>
GetWhereByIndex(item, mappingFieldsExpressions, it, 0) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 1) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 2)
).ToList();
}
else if (count == 4)
{
setList = list.Where(it =>
GetWhereByIndex(item, mappingFieldsExpressions, it, 0) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 1) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 2) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 3)
).ToList();
}
else if (count == 5)
{
setList = list.Where(it =>
GetWhereByIndex(item, mappingFieldsExpressions, it, 0) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 1) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 2) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 3) &&
GetWhereByIndex(item, mappingFieldsExpressions, it, 4)
).ToList();
}
else
{
Check.ExceptionEasy("MappingField max value is 5", "MappingField最大数量不能超过5");
}
return setList;
}
private static bool GetWhereByIndex(object item, List<MappingFieldsExpression> mappingFieldsExpressions, object it,int index)
{
var left = mappingFieldsExpressions[index].LeftEntityColumn.PropertyInfo.GetValue(it).ObjToString();

Loading…
Cancel
Save