mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-31 15:56:25 +08:00
Synchronization code
This commit is contained in:
parent
630011c752
commit
67f0341cf6
@ -283,6 +283,14 @@ namespace SqlSugar
|
||||
var reslt = method.Invoke(QueryableObj, new object[] { });
|
||||
return Convert.ToBoolean(reslt);
|
||||
}
|
||||
|
||||
public object ToTree(string childPropertyName, string parentIdPropertyName, object rootValue, string primaryKeyPropertyName)
|
||||
{
|
||||
var method = QueryableObj.GetType().GetMyMethod("ToTree", 4,typeof(string),typeof(string),typeof(object),typeof(string));
|
||||
var reslt = method.Invoke(QueryableObj, new object[] {childPropertyName,parentIdPropertyName,rootValue,primaryKeyPropertyName });
|
||||
return reslt;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Result Async
|
||||
@ -323,6 +331,13 @@ namespace SqlSugar
|
||||
var task = (Task)method.Invoke(QueryableObj, new object[] { pkValue });
|
||||
return await GetTask(task).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<object> ToTreeAsync(string childPropertyName, string parentIdPropertyName, object rootValue, string primaryKeyPropertyName)
|
||||
{
|
||||
var method = QueryableObj.GetType().GetMyMethod("ToTreeAsync", 4, typeof(string), typeof(string), typeof(object), typeof(string));
|
||||
var task =(Task)method.Invoke(QueryableObj, new object[] { childPropertyName, parentIdPropertyName, rootValue, primaryKeyPropertyName });
|
||||
return await GetTask(task).ConfigureAwait(false);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Helper
|
||||
|
@ -340,6 +340,16 @@ namespace SqlSugar
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<T> ToTree(string childPropertyName, string parentIdPropertyName, object rootValue, string primaryKeyPropertyName)
|
||||
{
|
||||
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
var pk = primaryKeyPropertyName;
|
||||
var list = this.ToList();
|
||||
Expression<Func<T,IEnumerable<object> >> childListExpression = (Expression<Func<T, IEnumerable<object>>>)ExpressionBuilderHelper.CreateExpressionSelectField(typeof(T),childPropertyName,typeof(IEnumerable<object>));
|
||||
Expression<Func<T, object>> parentIdExpression = (Expression<Func<T, object>>)ExpressionBuilderHelper.CreateExpressionSelectFieldObject(typeof(T), parentIdPropertyName);
|
||||
return GetTreeRoot(childListExpression, parentIdExpression, pk, list, rootValue) ?? new List<T>();
|
||||
}
|
||||
public List<T> ToTree(Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue, Expression<Func<T, object>> primaryKeyExpression)
|
||||
{
|
||||
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
|
@ -580,6 +580,15 @@ ParameterT parameter)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public async Task<List<T>> ToTreeAsync(string childPropertyName, string parentIdPropertyName, object rootValue, string primaryKeyPropertyName)
|
||||
{
|
||||
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
var pk = primaryKeyPropertyName;
|
||||
var list =await this.ToListAsync();
|
||||
Expression<Func<T, IEnumerable<object>>> childListExpression = (Expression<Func<T, IEnumerable<object>>>)ExpressionBuilderHelper.CreateExpressionSelectField(typeof(T), childPropertyName, typeof(IEnumerable<object>));
|
||||
Expression<Func<T, object>> parentIdExpression = (Expression<Func<T, object>>)ExpressionBuilderHelper.CreateExpressionSelectFieldObject(typeof(T), parentIdPropertyName);
|
||||
return GetTreeRoot(childListExpression, parentIdExpression, pk, list, rootValue) ?? new List<T>();
|
||||
}
|
||||
public async Task<List<T>> ToTreeAsync(Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue, object[] childIds)
|
||||
{
|
||||
var list = await this.ToListAsync();
|
||||
|
@ -240,9 +240,10 @@ namespace SqlSugar
|
||||
|
||||
Task<List<T>> ToParentListAsync(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue);
|
||||
Task<List<T>> ToParentListAsync(Expression<Func<T, object>> parentIdExpression, object primaryKeyValue, Expression<Func<T, bool>> parentWhereExpression);
|
||||
|
||||
List<T> ToTree(string childPropertyName, string parentIdPropertyName, object rootValue, string primaryKeyPropertyName);
|
||||
List<T> ToTree(Expression<Func<T,IEnumerable<object>>> childListExpression, Expression<Func<T,object>> parentIdExpression,object rootValue);
|
||||
List<T> ToTree(Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue, Expression<Func<T, object>> primaryKeyExpression);
|
||||
Task<List<T>> ToTreeAsync(string childPropertyName, string parentIdPropertyName, object rootValue, string primaryKeyPropertyName);
|
||||
Task<List<T>> ToTreeAsync(Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue);
|
||||
Task<List<T>> ToTreeAsync(Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue, Expression<Func<T, object>> primaryKeyExpression);
|
||||
List<T> ToTree(Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue, object[] childIds);
|
||||
|
@ -92,6 +92,19 @@ namespace SqlSugar
|
||||
LambdaExpression lambda = Expression.Lambda(funcType, property, parameter);
|
||||
return lambda;
|
||||
}
|
||||
public static Expression CreateExpressionSelectFieldObject(Type classType, string propertyName)
|
||||
{
|
||||
ParameterExpression parameter = Expression.Parameter(classType, "it");
|
||||
|
||||
|
||||
PropertyInfo propertyInfo = classType.GetProperty(propertyName);
|
||||
MemberExpression property = Expression.Property(parameter, propertyInfo);
|
||||
|
||||
UnaryExpression convert = Expression.Convert(property, typeof(object));
|
||||
var funcType = typeof(Func<,>).MakeGenericType(classType, typeof(object));
|
||||
LambdaExpression lambda = Expression.Lambda(funcType, convert, parameter);
|
||||
return lambda;
|
||||
}
|
||||
}
|
||||
internal static class LinqRuntimeTypeBuilder
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user