2

Closed

Suggestion: DirectoryServicesContext

description

Looking at the sample, you're manually creating DirectorySources, passing in a common root. I suggest that you follow the lead of LINQ to SQL and create a DirectoryContext type which accepts the root URI, and which will auto-matically instantiate DirectorySource fields. You could also forward the setting of the Log property if you wanted.
 
Then you could have:
 
class LocalContext: DirectoryServicesContext
{
[DirectorySearchScope(SearchScope.Subtree)]
public DirectorySource<User> Users;
 
public LocalContext(string uri)
: base(uri) // instantiates and stores root, instantiates Users
{
}
}
 
and
 
static void Main(string[] args)
{
var ldap = new LocalContext("LDAP://localhost");
 
var res1 = from usr in ldap.Users select usr;
 
// and nothing to prevent you from creating a new DirectorySource within that context:
 
var myUsers = ldap.GetDirectorySource<MyUser>(SearchScope.SubTree);
 
var res2 = from myUser in myUsers select myUser;
}
Closed Jul 16, 2010 at 7:58 AM by bdesmet
Fixed.

comments

bdesmet wrote Dec 3, 2007 at 5:42 AM

Hi Keith,

Thanks for the feedback - I'm aware of this issue but didn't consider it for implementation in the initial LINQ to LDAP sample series on my blog to reduce overhead. This RTM release is a straightforward adaption of the article series and hence the principle of having a data context hasn't made it to implementation. However, this principle has been applied in the LINQ to SharePoint project.

Over time I plan to update this project to follow the same design, maybe in a 1.1 release.

Thanks,
-Bart