Paging Suggestion: ToPage()

Feb 17, 2012 at 8:53 PM

As of right now, .ToPage() requires an integer to represent the page size but what if the max page size is set in the LdapConfiguration?

private static void SetupLDAPConfig()
{
    LdapConfiguration config = new LdapConfiguration();
    config = new LinqToLdap.LdapConfiguration();
    config.ConfigureFactory(ConfigurationSettings.AppSettings["computerName"]);
    config.AddMapping(new UserMapping());
    config.AddMapping(new GroupMapping());
    config.MaxPageSizeIs(2); // The paging adventure begins!
}

Meanwhile, when I start to query against LDAP...

//start paging
LinqToLdap.Collections.ILdapPage<string> firstPage = ldapContext.Query<User>()
       .Select(u => u.DisplayName).ToPage(2); // But I already set page size :(

Coordinator
Feb 17, 2012 at 10:23 PM

ToPage exists if you want to manually control paging.  Most LDAP servers specify a max number of results that can be returned for a request.  To make it easier for developers wanting all results without having to page manually, I use the max page size behind the scenes to automatically page the results if necessary.  I hope that clarifies things.

Feb 23, 2012 at 2:35 AM

Ah, I think I understand. So if we want to receive a result set that is divided among pages then we need to execute .ToPage() to receive a paging collection, BUT if we do not need our result set in a paging collection but want to change the max page size from the default value then we could call .MaxPageSizeIs() in our Ldap configuration?

Coordinator
Feb 25, 2012 at 3:01 PM

I think the key here is that all search requests in LINQ to LDAP are paged.  The question is is it being done for you or are you controlling it.  

MaxPageSizeIs exists only to protect against the infamous "Size limit was exceeded" error.  I default it to 500 which I believe is the max page size for OpenLDAP.  It's 1000 for Active Directory.  If you just want to issue queries then you could adjust MaxPageSizeIs to your directory's max and call it a day.  However, if you're building a list view and you have 30,000 entries in the directory you may not want to ToList your query.  In these situations you could use ToPage initially and then give the user the option to get all remaining results right now or piece-by-piece.

Does that explanation help?

Feb 29, 2012 at 4:31 AM

Yup, thanks!