I need to do basically what is done here
SELECT t.id, t.key
FROM
(
SELECT id, key, ROW_NUMBER() OVER (ORDER BY key) AS rownum
FROM datatable
) AS t
WHERE t.rownum % n = 0
ORDER BY t.key
but using Linq to Entities. I just can't figure out how. A method ROW_NUMBER is not known and using an index in the where clause gives me an error.
Query.Where((s, i) => i % n == 0);
Edit: more precisely
Query.Select((s, i) => new { index = i, data = s } ).Where(s => s.index % n == 0).Select(s => s.data)
The only solutions that worked for me so far is to temporarily run the SQL (toList
) and filter it afterwards. This however slows down my server significantly.