In a yak shaving accident I implemented a stripped down version of the OData provider. One can even say that it was a good exercise in understanding C# expression trees and LINQ queries. All that this library can do is transform a text query into an expression tree consumable by a LINQ provider.
It can recognise field names and even discern strings from numbers!
var expressionBuilder { get; } = new FilterExpressionBuilder<User>();
var filterStr = "userName eq 'Luke Skywalker'";
var expr = expressionBuilder.TranslateToExpression(filterStr);
var filtered = Users.Where(expr).ToList();
Assert.That(filtered.Count, Is.EqualTo(1));
Assert.That(filtered.First.UserName, Is.EqualTo("Luke Skywalker"));
public class User
{
public string UserName { get; set; }
}
- eq Equal
- ne Not equal
- gt Greater than
- lt Less than
- ge Grater than or equal
- le Less than or equal
- and And
- or Or
- Support both for camel case and pascal case field names in the text query
- Support for more than one operator at a time
- Bracket support
- Order by
- First
- Last
- string methods e.g. contains, endswith etc.
- Take
- Offset
- Escaping characters