views:

12

answers:

1

I'm trying to use 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.

A: 

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;
David B
Thing is I need to order the groups one way and then order the documents within each group by another value.
Gazeth