How To Reference Attributes Dynamically?

Dec 4, 2008 at 7: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 6: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 5:40 PM
Edited Nov 9, 2009 at 5:51 PM

Hi,

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 usr.cn.StartsWith("H") select usr;

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


 

If someone is interested i can elaborate.

 

Coordinator
Jul 14, 2010 at 5: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.

Cheers,
-Bart