Mapping directory syntaxes to .NET types

LinqToLdap will take care of the nitty-gritty of transmuting the directory data into CLR classes: all you have to do is define your directory object class.  This article explains which directory syntaxes map to which CLR classes and provides examples of each.  In the definition, I give the CLR type first and the C# type afterwards: the framework design guidelines recommend that you should use the  CLR type name to ensure cross-language interoperability.

Unicode String

oMSyntax: 64

Example: displayName

Maps to: System.String, string


oMSyntax: 127

Example: manager

Maps to: System.String, string


oMSyntax: 2

Examples:  userAccountControl, logonCount

Maps to: System.Int32, int

Note: in version 2.0.2, <not set> is translated to 0 (zero).

Large Integer/Interval

oMSyntax: 65

Examples:  uSNCreated, uSNChanged, pwdLastSet, lastLogonTimestamp

Maps to: System.Int64, long

Note: in version 2.0.2, <not set> is translated to 0 (zero).

Generalized Time

aka UTC Coded Time

oMSyntax: 24

Examples:  whenCreated, whenChanged

Maps to: System.DateTime

Note: in version 2.0.2, <not set> is translated to 0 (zero).

Octet String

oMSyntax: 4

Example:  objectGuid

Maps to: System.Guid


oMSyntax: 4

Example:  objectSid

Maps to: System.Security.Principal.SecurityIdentifier

Additional Notes

Sometimes, it’s necessary to know the purpose of the attribute to be able to interpret it.  For example, pwdLastSet is a Large Integer/Interval but it’s used to store a datetime (note the lack of PascalCasing, there) so LinqToLdap will translate it as an Int64 or DateTime, depending on how you map it:

Map(x => x.lastLogonTimestamp).StoreGenerated();

will map to an Int64, whereas,

Map(x => x.lastLogonTimestamp).DateTimeFormat(null).StoreGenerated();

will map to a DateTime.  Note that in version 2.0.2, <not set> is translated to 0 (zero) (which may be translated to “01/01/0001 00:00:00” if you’ve gone for DateTimeFormat(null).


If there are any I’ve missed, please let me know and I’ll add them.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: