Anybody know how to write a LINQ to SQL statement to return every nth row from a table? I\'m needing to get the title of the item at the top of each page in a paged data gr
Sometimes, TSQL is the way to go. I would use ExecuteQuery here:
var data = db.ExecuteQuery(@"
SELECT * FROM
(SELECT *, ROW_NUMBER() OVER (ORDER BY id) AS [__row]
FROM [YourTable]) x WHERE (x.__row % 25) = 1");
You could also swap out the n:
var data = db.ExecuteQuery(@"
DECLARE @n int = 2
SELECT * FROM
(SELECT *, ROW_NUMBER() OVER (ORDER BY id) AS [__row]
FROM [YourTable]) x WHERE (x.__row % @n) = 1", n);