Skip and Take not working as expected
Posted: Tue 08 Oct 2013 01:34
Hi, I'm using LinqConnect 4.2.338 with Postgres. I am trying to implement paging in my application, and I see that when I use Skip(X).Take(Y), my queries are returning the skip count of X rows instead of the take count of Y rows. I've recreated this outside my full application with the tiny routine seen below.
This results in
You can see by the result IDs that it's skipping properly, but it's returning the wrong number of rows. How can I get it to return just the "take" number of rows?
Cheers -- Michael Watson
Code: Select all
using (
var dc = new ABCDataContext("User Id=ABC;Password=ABC;Host=localhost;Database=blueridge;Schema=public")
)
{
var skip = 0;
var take = 100;
var readSoFar = 0;
while (readSoFar < 1000)
{
var query = from it in dc.AuditRecords
orderby it.Id
select it;
var results = query.Skip(skip).Take(take);
Console.WriteLine("skip={0},take={1},resultCount={2}, first-result-id={3}", skip, take, results.Count(), results.First().Id);
readSoFar += results.Count();
skip += results.Count();
}
}
Code: Select all
skip=0,take=100,resultCount=100, first-result-id=48701
skip=100,take=100,resultCount=100, first-result-id=48801
skip=200,take=100,resultCount=200, first-result-id=48901
skip=400,take=100,resultCount=400, first-result-id=49101
skip=800,take=100,resultCount=800, first-result-id=49501
Cheers -- Michael Watson