I would like to filter my List for Reporting purposes but i would like to make it as dynamic as possible so that the user can Filter on 1 or more columns.
The idea i have is to create a Dictionary and then pass that to a method that will filter out the relevant records but i am now stuck as to how i would do the "Dynamic" part.
This is how my current code looks so far but it is not working.
filters = {CourseId,2},{CourseDescription,Maths}
public IQueryable<Course> Filter(Dictionary<string,string> filters)
{
var a = from s in context.Courses
select s;
foreach (var filter in filters)
{
if(!string.IsNullOrEmpty(filter.Value))
{
a = a.Where(s => s./*filter.Key*/.ToUpper().Contains(/*filter.value*/.ToUpper()));
}
}
}
Please can someone assist and point me into the correct direction so that i can get this working.
Thank you.