I need to create functionality that would allow users to filter entities using literal queries (i.e. age gt 20 and name eq 'john'
). Is there a provided functionality to do this in C#/Asp.Net MVC or do I have to parse this query by myself?
I found that OData implies having exactly such functionality (OData Filter Expressions MSDN). However, I'm not familiar with it so I don't know how to implement such behavior in my project.
I need something like this:
var list = new List<Person>
{
new Person { Name = "John", Age = 30 },
new Person { Name = "Hanna", Age = 25 },
new Person { Name = "John", Age = 15 }
};
string query = "age gt 20 and name eq /'John/'";
IEnumerable<Person> result = list.FilterByExpression(query);
// returns list with John aged 30
Any advice would be appreciated.