mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-26 10:19:40 +08:00
Optimized code
This commit is contained in:
@@ -352,7 +352,7 @@ namespace SqlSugar
|
||||
{
|
||||
var childName = ((childListExpression as LambdaExpression).Body as MemberExpression).Member.Name;
|
||||
string parentIdName = GetParentName(parentIdExpression);
|
||||
return UtilMethods.BuildTree(list, pk, parentIdName, childName, rootValue)?.ToList() ?? default;
|
||||
return UtilMethods.BuildTree(this.Context,list, pk, parentIdName, childName, rootValue)?.ToList() ?? default;
|
||||
}
|
||||
|
||||
private static string GetParentName(Expression<Func<T, object>> parentIdExpression)
|
||||
|
||||
@@ -19,12 +19,12 @@ namespace SqlSugar
|
||||
public class UtilMethods
|
||||
{
|
||||
|
||||
public static IEnumerable<T> BuildTree<T>(IEnumerable<T> list, string idName, string pIdName, string childName, object rootValue)
|
||||
public static IEnumerable<T> BuildTree<T>(ISqlSugarClient db,IEnumerable<T> list, string idName, string pIdName, string childName, object rootValue)
|
||||
{
|
||||
var type = typeof(T);
|
||||
var mainIdProp = type.GetProperty(idName);
|
||||
var pIdProp = type.GetProperty(pIdName);
|
||||
var childProp = type.GetProperty(childName);
|
||||
var entityInfo = db.EntityMaintenance.GetEntityInfo<T>(); ;
|
||||
var mainIdProp = entityInfo.Type.GetProperty(idName);
|
||||
var pIdProp = entityInfo.Type.GetProperty(pIdName);
|
||||
var childProp = entityInfo.Type.GetProperty(childName);
|
||||
|
||||
var kvList = list.ToDictionary(x => mainIdProp.GetValue(x).ObjToString());
|
||||
var group = list.GroupBy(x => pIdProp.GetValue(x).ObjToString());
|
||||
|
||||
Reference in New Issue
Block a user