Thursday, July 31, 2008 2:18 PM bart

LINQ to AD - Refresh Release 1.0.1 Available

I’m happy to announce the availability of the 1.0.1 RR (Refresh Release, not Dutch for “Rechtvaardige Rechters” – known as Knights of Christ – a stolen piece of art by Jan Van Eyck in my student-home city Ghent) of LINQ to AD on CodePlex. Here’s the Change Set 12012’s description:

Refresh Release 1.0.1 - Includes bug fixes and support for:
- byte[]- and GUID-valued directory attributes
- Bug fix for non-constant EndsWith, BeginsWith and Contains clauses
- Introduction of DirectoryContext with support for nested contexts and direct update support
- Updated samples to use the new available features

In practice this means that some common issues reported by users have been addressed (more to follow in subsequent refreshes) and a first level of (opt-in) support for “directory contexts” has been added. This means you can create an entity model like this:

    sealed class MyContext : DirectoryContext
    {
        public MyContext(DirectoryEntry searchRoot)
            : base(searchRoot)
        {
        }

        [DirectorySearchOptions(SearchScope.Subtree)]
        public DirectorySource<User>  Users  { get; set; }

        [DirectorySearchOptions(SearchScope.Subtree)]
        public DirectorySource<Group> Groups { get; set; }

        [DirectorySearchPath("OU=Demo")]
        public MyDemoContext          Demo   { get; set; }
    }

    sealed class MyDemoContext : DirectoryContext
    {
        public MyDemoContext(DirectoryEntry searchRoot)
            : base(searchRoot)
        {
        }

        public DirectorySource<MyUser> Users  { get; set; }
    }

where the classes User, Group and MyUser are defined entity types as in previous releases (now also support GUID-valued properties). What’s new though is the fact we have a DirectoryContext base class you can inherit from to create a custom context that contains a mapping of various query data sources for your directory structure. Moreover, this mechanism supports hierarchical contexts that reflects the structure of the directory (which, in combination with the use of DirectorySearchOptionsAttribute can be controlled with respect to the used search scope – Base, OneLevel or Subtree). For example, in the code above the MyContext class contains a property called Demo:

        [DirectorySearchPath("OU=Demo")]
        public MyDemoContext          Demo   { get; set; }

which is annotated with a DirectorySearchPathAttribute that specifies the path relative to the parent context (specified for MyContext using the constructor), so if you write:

var ctx = new MyContext(new DirectoryEntry(“LDAP://localhost/DC=bartdesmet,DC=local”));
var res = from u in ctx.Demo.Users …;

you’re effectively querying for user objects under LDAP://localhost/OU=Demo,DC=bartdesmet,DC=local. Notice I’m using another entity type for the nested context – there’s no need to do so, you can reuse the User entity type there but – as illustrated above – you’re not required to do so (for example, because under OU=Demo, you’d like to query on more directory attributes than elsewhere).

Another notable feature is the support for extension methods on DirectoryEntry and DirectorySearcher. In other words, you can write something like:

DirectoryEntry myDirectory = new DirectoryEntry(…);
var res = from u in myDirectory.AsQueryable<MyUser>(SearchScope.Subtree) …;

This allows users to perform direct querying starting from well-known System.DirectoryServices classes simply by importing the extension methods in the BdsSoft.DirectoryServices.Linq namespace and using AsQueryable to lift those entry-points to a LINQ to AD supported DirectorySource<T>. The fact DirectorySearcher is now supported as well makes it possible to specify much more options (such as time outs, client-side caching behavior, tombstone object inclusion, etc) than was possible before. If you want to make DirectorySearcher capabilities available through a strongly-typed DirectoryContext object, it’s possible to use a constructor overload that takes a DirectorySearcher object.

The new release can be downloaded here. Enjoy!

PS: Updates for LINQ to SharePoint are coming up as well.

Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

Filed under:

Comments

# Link Listing - July 31, 2008

Thursday, July 31, 2008 8:28 PM by Christopher Steen

ASP.NET How to Encrypt Query String Parameters in ASP.NET [Via: Keyvan Nayyeri ] Using client templates,...

# Link Listing - July 31, 2008

Thursday, July 31, 2008 8:29 PM by Christopher Steen

Link Listing - July 31, 2008

# Reflective Perspective - Chris Alcock &raquo; The Morning Brew #149

Pingback from  Reflective Perspective - Chris Alcock  &raquo; The Morning Brew #149

# Dew Drop - August 1, 2008 | Alvin Ashcraft's Morning Dew

Pingback from  Dew Drop - August 1, 2008 | Alvin Ashcraft's Morning Dew