Search Wiki:

Introduction

LINQ to Active Directory implements a custom LINQ query provider that allows querying objects in Active Directory. Internally, queries are translated into LDAP filters which are sent to the server using the System.DirectoryServices .NET Framework library. LINQ stands for Language Integrated Query and is one of the core features of Microsoft's .NET Framework 3.5 release. More information can be found via the MSDN website on http://msdn.microsoft.com.

Features


  • Translates into LDAP filters according to RFC 2254.
  • Simple and approachable entity model with support of propagating updates back.
  • Supports mappings to both the System.DirectoryServices (.NET) and ActiveDs (COM) APIs.
  • Ships with a set of samples.

Disclaimer


This project is meant as a basic sample on implementing custom LINQ query providers. It hasn't been tested thoroughly and we do not provide any support whatsoever. Do not use it in a production environment without proper testing and validation of the technology's behavior. Users are most welcome to report issues and bugs through the Issue Tracker on this site.

Samples


C# sample


    // NOTE: Entity type definition "User" omitted in sample - see samples in release.
 
    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 == "2525"
              select new { Name = usr.FirstName + " " + usr.LastName, usr.Office, usr.LogonCount };
 
    foreach (var u in res)
    {
        Console.WriteLine(u);
        u.Office = "5252";
        u.SetPassword(pwd);
    }
 
    users.Update();


Visual Basic sample


    ' NOTE: Entity type definition "User" omitted in sample - see samples in release.
 
    Dim users As New DirectorySource(Of User)(ROOT, SearchScope.Subtree)
    users.Log = Console.Out
 
    Dim res = From usr In users
              Where usr.FirstName.StartsWith("B") And usr.Office = "2525"
              Select New With { Name = usr.FirstName + " " + usr.LastName, usr.Office, usr.LogonCount }
 
    For Each u In res
        Console.WriteLine(u)
        u.Office = "5252"
        u.SetPassword(pwd)
    Next
 
    users.Update()


About the project founder


A former Visual C# MVP, Bart De Smet now works at Microsoft Corporation on the WPF dev team in an SDE role. Prior to this new challenge, Bart was active in the Belgian community evangelizing various Microsoft technologies, most of the time focusing on CLR, language innovation and frameworks. In his evangelism role, he's been speaking at various events and attended several international conferences including TechEd Europe, IT Forum and the PDC. In 2005, Bart graduated as a Master of Informatics from Ghent University, Belgium. Two years later, Bart became a Master of Computer Science Software Engineering from the same university.

You can visit Bart's blog on http://blogs.bartdesmet.net/bart
Last edited Nov 29 2007 at 8:37 AM  by bdesmet, version 6
Comments
jacodv wrote  Jan 22 at 11:26 AM  
Great work!

Q: I want to build a POC using your sample. What do I need to do to add functionality to show all users plus a domain selection similar to that of Windows? My customer has multiple domains in AD and users need to select various email addresses.

Regards
Jaco

bdesmet wrote  Feb 28 at 9:39 PM  
Hi jacodv,

Sorry for the late reply - can you drop me a mail at bartde@microsoft.com with some more information on your scenario?

Thanks,
-Bart

Updating...