This project is read-only.

hyphenated attributes, anonymous query by example use

Jun 29, 2013 at 12:58 AM
For some reason I thought I had this sorted out before, but today I could not find any information to back that thought up. If I am missing an easy feature of LinqToLdap, please let me know.

I very much like working with the anonymous, query by example form. But have come upon a number of AD attributes that are hyphenated (mycompany-management-accounttype, having a single character value specifying the type of account, for an example).

As best I could work out, to be able to accomplish what I want, the only option I have is to modify the PropertyMappingBuilder class so that I can query as shown here

var resourceQuery = resourceContext.Query(
new { Cn = "", useraccountcontrol = 0, DistinguishedName = "", mycompany__management__accounttype = "" },

The double underbar I thought a suitable replacement for '-', and this correctly maps to the desired attribute name, given the following one line change to PropertyMappignBuilder

AttributeName = AttributeName ?? (!type.IsAnonymous() ? PropertyInfo.Name : PropertyInfo.Name.Replace("__", "-")),

I would prefer to have come up with a more elegant solution, but this one line change resolves my immediate concern.

If I am not missing an existing extension point in the project, could I suggest something like this for inclusion in the future?

Jun 29, 2013 at 9:04 PM
Outside of using DirectoryAttributes the solution you came up with is the correct one. Anonymous objects use auto mapping which can only infer the attribute name from the property names. This feature makes sense so I'll go ahead and create a feature request for it. You should be able to use a single underscore and always replace it since underscores are not considered valid characters for attribute names.
Jun 29, 2013 at 9:05 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.