If I use:
private List<string> GetDataFrom()
{
var result = new List<string>();
using (var context = new mainEntities())
{
var matches = context.data.Where(s => s.Width == 500).ToList();
result.AddRange(matches.Select(t => t.Key));
}
return result;
}
It is giving me perfect results, but I want to use a method where I can use column name and value, like this:
private List<string> GetDataFrom(string columnName, int valToMatch)
{
var result = new List<string>();
using (var context = new mainEntities())
{
var propertyInfo = typeof(data).GetProperty(columnName).Name;
var matches = context.data
.Where(p => p.propertyInfo == valToMatch);
result.AddRange(matches.Select(t => t.Key));
}
return result;
}
This Method obviously doesn't work, so how can I do the same? I am using SqlLite, so some answers given do not apply. The whole problem is using propertyInfo the wrong way.
I tried various different approaches but no success.
This question is not a duplicate, because the suggested questions and their answers do not help much. I like this question to be reopened. I have found an answer myself I like to share.