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.
精彩评论