I'm using the following code to query my database:
private const int PAGE_SIZE = 10;
public static IList<Image> GetTopImagesForUser(String connectionString, int userID, int page)
{
dbDataContext db = new dbDataContext(connectionString);
var images = (from p in db.Images
where (p.SubmitterUserIndex == userID &&
p.URL != "none" &&
p.ThumbURL != "none")
orderby p.Rep descending
select p).Skip(page * PAGE_SIZE).Take(PAGE_SIZE);
/* snip */
return topImages;
}
If I call this code with a page of 0, everything works the way I want it to - I get a nicely ordered list, 10 results, everything is correct.
If I call this code with a page of 1, however, rows that were in page 0 end up in page 1. I can't even begin to understand why. I've checked my database for duplicate rows, none. I've checked to make sure every row's URL and ThumbURL are not "none". That's not the problem either. I've checked to make sure page is what I expect it to be when I call this method, and it is always what I expect it to be.
What really baffles me is that the following method, which differs from the first method only in the orderby clause, works completely as expected.
public static IList<Image> GetAllImagesForUser(String connectionString, int userID, int page)
{
dbDataContext db = new dbDataContext(connectionString);
var images = (from p in db.Images
where (p.SubmitterUserIndex == userID &&
p.URL != "none" &&
p.ThumbURL != "none")
orderby p.SubmitTime descending
select p).Skip(page * PAGE_SIZE).Take(PAGE_SIZE);
/* snip */
return allImages;
}
Has anyone run into something like this? Is there a different form that my query should take to do what I want it to do? I'm not sure what I could be missing.