How do you page IGrouping on the grouped items rather than the group
I'm trying to us开发者_运维知识库e skip and take on IGrouping but I don't want to page on the grouped key I want to do it on the items that have been grouped.
You could page them before you group them.
it's pretty easy to page this stuff in-memory:
var page =
(
from g in groups
from item in g
select item
).Skip(100).Take(20);
It doesn't translate into sql very well - which is why no one is answering. The issue is that when you ask for the elements of a group, linq To Sql re-queries the database by group key to get those elements. That's why it's better to order and page without grouping.
You can achieve conditional ordering by using the ternary operator:
var query =
from c in Customers
order c by
c.Name.StartsWith("B") ? 1 :
c.Orders.Any() ? 2 :
3,
c.Name
select c;
精彩评论