How To Reference Attributes Dynamically?

Dec 4, 2008 at 8:51 PM
I see that your user class has predefined list of attributes. How would one reference a passin attribute name? Or an attribute that you don't know ahead of time?
Jun 14, 2009 at 7:32 AM

There's not a way to do this.

The entities.cs file contains all that a user will ever contain within the scope of your project.  Any attribute that you may require needs to be defined within this Entities.cs.

Nov 9, 2009 at 6:40 PM
Edited Nov 9, 2009 at 6:51 PM


For my own need, i have added an anonymous type support that allow to skip (for simple read-only use case) the "pre-declare entities" process. It goes like this:



            var users = DirectorySource.CreateInstance(ROOT, SearchScope.Subtree, "user", new
                    cn = default(string),
                    distinguishedName = default(string),
                    whenCreated = default(DateTime),
                    lastLogon = default(DateTime),
                    memberOf = default(string[])

            var res1 = from usr in users where"H") select usr;

            foreach (var w in res1)
                Console.WriteLine("cn: {0}\nlastLogon: {1}\nmemberOf: \n{2}\n",, w.lastLogon, String.Join("\n- ",w.memberOf));


If someone is interested i can elaborate.


Jul 14, 2010 at 6:25 AM

This is definitely a good technique to work around the issue you uncovered. In fact, this is related to phantom types found in functional languages like Haskell. An upcoming version of LINQ to AD may support this.