C#: access a class property when the property identifier is known as a string

Posted by Hans on Stack Overflow See other posts from Stack Overflow or by Hans
Published on 2010-05-19T11:17:00Z Indexed on 2010/05/19 11:20 UTC
Read the original article Hit count: 318

Filed under:
|
|
|

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 :(

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ