How to use orderby in IQueryable object?
+1
A:
You use it like so:
var orderedResult = yourContext.YourTable
.OrderBy(yt => yt.SomeValueThatYouWantTheResultOrderedBy);
klausbyskov
2010-04-23 08:22:17
no i mean i call a function where the Linq to Entities query is written and it returns the IQueryable object.I want to apply orderby and skip and take extension methods to this object.
bbbbb
2010-04-23 08:53:04
@bbbbb How is that different? In the above example `yourContext.YourTable` is an IQueryable.
klausbyskov
2010-04-23 09:24:34
+1
A:
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.
Prutswonder
2010-04-23 09:36:24