tags:

views:

147

answers:

2

is there a way to select one per every 5 records in sql server with linq?

+2  A: 
.Skip(5).Take(1);

If you want a more descriptive answer then please post your code.

Ian Roke
is skip also a sql keyword?
This selects just *one* record, the *sixth* item in the collection. I guess the OP needs one in each five.
Mehrdad Afshari
No, skip is *not* a SQL keyword - it's one of the standard operators in the LINQ functionality ste.
marc_s
+3  A: 

I don't think it's possible to do server side directly with LINQ to SQL. There is a client side solution, however:

 var result = new DataContext().Table.AsEnumerable()
                     .Select((x, i) => new { Index = i, Item = x })
                     .Where(t => t.Index % 5 == 0).Select(t => t.Item);
Mehrdad Afshari