【发布时间】:2011-08-29 19:31:26
【问题描述】:
2019-01-31 编辑:Latest solution
我已经按照示例 here 和 here 创建了一个带有成员表达式的通用排序,但我不知道应该如何添加“ThenBy”子句,或者组合多个列进行排序方法调用表达式。理想情况下,ThenBy 应该在 skip 之前,但它不能,因为它看不到我使用 methodcallexpression 制作的 orderby 子句。 GridSortExpression 是一个 Telerik 类 - 它只描述查询应该排序的列和方向。
谁能解释一下?这是我现在拥有的:
Dim exp As Expressions.Expression(Of Func(Of Product_Catalog, Boolean)) = PredicateBuilder.True(Of Product_Catalog)()
exp = exp.And(Function(e) e.Chapter_Price > 30)
Dim sortExpression As New List(Of GridSortExpression)({New GridSortExpression() With {.SortOrder = GridSortOrder.Descending, .FieldName = "Id"}})
If sortExpression.Count = 0 Then
catalogList = con.Product_Catalogs.AsExpandable.Where(exp).OrderBy(Function(o) o.Item_Type).ThenBy(Function(o) o.Item_Description).Skip(startRowIndex).Take(maximumRows).ToList
Else
Dim param As ParameterExpression = Expression.Parameter(GetType(Product_Catalog), String.Empty)
Dim prop As MemberExpression = Expression.PropertyOrField(param, sortExpression(0).FieldName)
Dim sort As LambdaExpression = Expression.Lambda(prop, param)
Dim source = con.Product_Catalogs.AsExpandable.Where(exp)
Dim resultExp As MethodCallExpression
resultExp = Expression.[Call](GetType(Queryable), "OrderBy" & If(sortExpression(0).SortOrder = GridSortOrder.Descending, "Descending", ""), _
New Type() {GetType(Product_Catalog), prop.Type}, con.Product_Catalogs.AsExpandable.Where(exp).Expression, Expression.Quote(sort))
catalogList = source.Provider.CreateQuery(Of Product_Catalog)(resultExp).Skip(startRowIndex).Take(maximumRows).ToList
End If
【问题讨论】:
-
虽然,这并不是我在 11 年所寻找的,但这篇文章可能会对遇到类似问题的人有所帮助:codeproject.com/Articles/280952/…
-
我的latest implementation这个问题