dynamic user = context.Query("CN=Users,CN=Employees,DC=Northwind,DC=local") .Select(new[]{"cn", "givenname", "sn", "telephonenumber"}) .FilterWith("cn=Andrew Fuller") .FirstOrDefault(); Console.WriteLine(user.cn); Console.WriteLine(user.givenname); Console.WriteLine(user.sn); Console.WriteLine(user.telephonenumber);
I added a Select extension that takes an array of strings so you still get projection support. FilterWith is the only way to query since everything else uses expressions (you can't use dynamic types in expressions). The only type support you get here is what can come back from the directory so that's string, string[], and byte[]. Also, property names will always be lower case so even though it may be givenName in the directory, use givenname to access it. That's just how DirectoryServices.Protocols rolls.
No comments:
Post a Comment