Reputation: 13614
I am using entity framework 6 code first approach.
At some point I get from the user a string, table name and column name.
I need to fetch records using table name and column name.
Any idea how can I implement it using LINQ?
Upvotes: 1
Views: 1316
Reputation: 859
Following the Hemdip link, you can use reflection to get what you want :
var table = (IEnumerable)context.GetType().GetProperty(tableName).GetValue(context, null);
List<object> results = new List<object>();
foreach(var line in table)
{
var value = line.GetType().GetProperty(propertyName).GetValue(line, null);
if(value == searchValue) {
results.Add(line);
}
}
Upvotes: 1