问题描述
我创建了一个函数具有follwing参数:
I have created a function that has the follwing parameter:
List<Expression<Func<CatalogProduct, bool>>> orderBy = null
此参数是可选的,如果它充满应该为我创造一个ORDER BY和比构建适应和支持,让我可以订购SQL服务器上的结果。
This parameter is optional, If it is filled it should create a order by and than by constuction for me, so that I can order the result on the SQL server.
我想:
IOrderedQueryable temp = null;
foreach (Expression<Func<CatalogProduct, bool>> func in orderBy)
{
if (temp == null)
{
temp = catalogProducts.OrderBy(func);
}
else
{
temp = temp.ThanBy(func);
}
}
但不是没有reconized。是否有人知道我怎么能解决这个问题?
But the than By is not reconized. Does someone know how I can solve this problem?
我把它改为.ThenBy(),但是这只是.OrderBy(后直接允许的),而不是在一个IOrderedQueryable
I changed it to .ThenBy() but this is only allowed directly after the .OrderBy() and not on a IOrderedQueryable
所以临时= catalogProducts.OrderBy(FUNC).ThenBy(FUNC);是允许的,但临时= catalogProducts.OrderBy(FUNC);临时= temp.ThenBy(FUNC); issn't
so temp = catalogProducts.OrderBy(func).ThenBy(func); is allowed but temp = catalogProducts.OrderBy(func); temp = temp.ThenBy(func); issn't
任何其他建议?
推荐答案
两个问题;首先, ThanBy
应 ThenBy
;其次, ThenBy
仅在通用的类型, IOrderedQueryable&LT; T&GT;
Two problems; firstly, ThanBy
should be ThenBy
; secondly, ThenBy
is only available on the generic type, IOrderedQueryable<T>
.
于是更改为:
IOrderedQueryable<CatalogProduct> temp = null;
foreach (Expression<Func<CatalogProduct, bool>> func in orderBy) {
if (temp == null) {
temp = catalogProducts.OrderBy(func);
} else {
temp = temp.ThenBy(func);
}
}
和你应该进行排序。
这篇关于LINQ多个订单由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!