Generic Lambda Query Builder
The class is called
ExpressionBuilder. It has three properties:
One public method
GetExpression that returns the lambda expression, and three private methods:
All the methods are explained in details in the examples.
ConstantExpression must be the same type of the
MemberExpression. The value in this example is a string, which is converted before creating the
GetExpression Private overload
For one filter:
Here is where the query is created, it receives a expression parameter and a filter.
For two filters:
It returns the BinaryExpresion instance instead of the simple Expression.
This class holds predicate filters values.
Enum to hold the operations values:
Collection filters = new List();
QueryFilter filter = new QueryFilter("Name", "Burger", Operator.StartsWith);
In this case, it is a query against the Food entity, that want to find all foods that start with "Burger" in the name.
This modified text is an extract of the original Stack Overflow Documentation created by following contributors
and released under CC BY-SA 3.0