Getting odd/even part of a sequence with LINQ

If you’re using LINQ to SQL or LINQ to Entities you should first fully materialize the results into memory:

var oddCategories  = projectsByCat.ToList().Where((c,i) => i % 2 != 0);
var evenCategories = projectsByCat.ToList().Where((c,i) => i % 2 == 0);

It isn’t possible to iterate through results on the database with an indexer without the use of a cursor, which either ORM framework does not do.

Leave a Comment