开发者

How to use orderby in IQueryable object?

How to use orderby in IQuery开发者_开发知识库able object?


You use it like so:

var orderedResult = yourContext.YourTable
        .OrderBy(yt => yt.SomeValueThatYouWantTheResultOrderedBy);


From the comment of klausbyskov's answer, your question should be: How do I convert an IOrdereQueryable into an IQueryable object?

In that case, you should convert it to a List object first (which means the query will be executed), and then perform a select on the resulting list:

var orderedList = (
    from q in MyDataContext.MyTable 
    orderby q.SortColumn 
    select q
    ).ToList();
var queryableList = orderedList.Select(q => q);

Note: As I said, the orderedList will be evaluated, so I wouldn't recommend using it for large datasets.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜