Paging not working as expected

May 23 at 2:15 PM
Edited May 23 at 3:07 PM
Hi

I seem to have run into a snag with paging. I know Active Directory usually has a maximum page size of 1000. So, in my code, I'm using query.InPagesOf(900) just to be on the safe side.

When I first wrote that, I tested in my lab that has about 100 users. So I set query.InPagesOf(10), and verified that I'd get all results (I do). So I figured things work as desired.

Now I'm in the productive environment, and query.InPagesOf(900) gets me 900 results. query.InPagesOf(100) gets me 100 results, query.InPagesOf(1000) gets me 1000 results, and so forth. So basically, the value I give to InPagesOf is the maximum number of results I get.

When I change the code to automatic paging, so query.ToList(), then I get 500 results (I guess that's the default page size then). But that leaves out everything above 500.

Then I tried manual paging as described here: https://linqtoldap.codeplex.com/wikipage?title=Paging

But, page.HasNextPage is always false.

So, how do I get all results without blowing up whatever maximum search result size the LDAP server has set?

Thanks

@edit, I wrote this generic method as a workaround
    private List<T> readPagedManual<T>(IQueryable<T> query, int pageSize)
        {
            if (pageSize > 0)
            {
                List<T> results = new List<T>();
                int nbPages = 1;
                List<T> page = query.Take(pageSize).ToList();
                results.AddRange(page);
                while (page.Count == pageSize)
                {
                    page = query.Skip(nbPages * pageSize).Take(pageSize).ToList();
                    results.AddRange(page.);
                    nbPages++;
                }
                return results;
            }
            else
            {
                return query.ToList();
            }
        }
And while that works, it returns duplicate items (and it requires an OrderBy statement in the query). I can filter out the duplicates and thus arrive at what I want, but I'd really like to get paging working the way it was meant to be used.