C#: access a class property when the property identifier is known as a string
- by Hans
Hi,
I'm using LINQ to Entities on a database which structure is not known in advance. I use reflection to retrieve the information, and now have a list of strings with all the table names. Because I use LINQ, I also have the datasource encapsulated in a C# class (linqContext), with each table being a property of that class.
What I want to achieve is this:
Assume one of the strings in the table names list is "Employees". This is known in code, I want to do the following:
linqContext.Employees.DoSomethingHere();
Is this possible? I know that if all the propertie were just items in a list, I could use the string as indexer, linqContext["Employees"]. However, this is not the case :(