internal static Dictionary <MethodInfo, Expression> Gather(Expression expression) { var gatherer = new OrderGatherer(); gatherer.Visit(expression); return(gatherer.orderBys); }
/// <summary> /// 当客户端排序定义为空时,使用预定义的排序表达式。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="source"></param> /// <param name="orderPredicate"></param> /// <returns></returns> private static IQueryable <T> UseDefinitionQuery <T>(IQueryable <T> source, Expression <Func <IQueryable <T>, IQueryable <T> > > orderPredicate) { var sourceType = typeof(T); var parExp = Expression.Parameter(sourceType, "s"); var orderBys = OrderGatherer.Gather(orderPredicate.Body); var expression = source.Expression; foreach (var kvp in orderBys) { expression = Expression.Call(null, kvp.Key, new[] { expression, kvp.Value }); } return(source.Provider.CreateQuery <T>(expression)); }