Sunday, November 25, 2007 11:23 PM
bart
LINQ to Active Directory (formerly known as LINQ to LDAP) is here
Within a few seconds from now I'll hit the "Publish This Project" button in CodePlex. Back in the early Orcas ages (beta 1 and before) I cooked up this pretty simple example showing how to create custom LINQ query providers. As a matter of fact, it was the result of a blog series back in April entitled "The IQueryable tales". Here are the pointers but keep in mind things have changed in the meantime:
More specifically, the API to write custom LINQ query providers has changed a bit. Most notably is the change that happened in Orcas Beta 2 refactoring the IQueryable<T> interface into IQueryable<T> and IQueryProvider. The new design might be slightly harder to implement (or to wrap your head around initially) but it certainly helps to separate concerns (something that's "queryable" versus the "construction work" that needs to be performed when building up the expression tree). If time permits, I'll reiterate the blog series based on the Orcas RTM APIs.
Now renamed as LINQ to Active Directory (or short: LINQ to AD), this sample allows to write things like this:
var users = new DirectorySource<User>(ROOT, SearchScope.Subtree);
users.Log = Console.Out;
var res = from usr in users
where usr.FirstName.StartsWith("B") && usr.Office == "10/2525"
select new { Name = usr.FirstName + " " + usr.LastName, usr.Office, usr.LogonCount };
foreach (var u in res)
{
Console.WriteLine(u);
u.Office = "10/5252";
u.SetPassword(pwd);
}
users.Update();
That's right: we have an entity model in place (see samples in the release for more info), allow to do nice mappings (e.g. Office stands for "physicalDeliveryOffice" in AD's User object class), have a simple API that allows adding methods on entities (e.g. SetPassword is a one-line piece of code) and there's update support (change properties as much as you want, just call Update on the DirectorySource object to feed changes back). Cool huh?
So, here it is NOW: LINQ to AD. Enjoy!
Del.icio.us |
Digg It |
Technorati |
Blinklist |
Furl |
reddit |
DotNetKicks
Filed under: LINQ