Tutorial by Examples

This class holds predicate filters values. public class QueryFilter { public string PropertyName { get; set; } public string Value { get; set; } public Operator Operator { get; set; } // In the query {a => a.Name.Equals("Pedro")} // Property name to filter ...
public static Expression<Func<T, bool>> GetExpression<T>(IList<QueryFilter> filters) { Expression exp = null; // Represents a named parameter expression. {parm => parm.Name.Equals()}, it is the param part // To create a ParameterExpression need the ty...
For one filter: Here is where the query is created, it receives a expression parameter and a filter. private static Expression GetExpression<T>(ParameterExpression param, QueryFilter queryFilter) { // Represents accessing a field or property, so here we are accessing for example: ...
ConstantExpression must be the same type of the MemberExpression. The value in this example is a string, which is converted before creating the ConstantExpression instance. private static ConstantExpression GetConstant(Type type, string value) { // Discover the type, convert it, and create Co...
Collection filters = new List(); QueryFilter filter = new QueryFilter("Name", "Burger", Operator.StartsWith); filters.Add(filter); Expression<Func<Food, bool>> query = ExpressionBuilder.GetExpression<Food>(filters); In this case, it is a query against the...

Page 1 of 1