public override Expression <Func <T, bool> > ToExpression() { Expression <Func <T, bool> > leftExpression = left.ToExpression(); Expression <Func <T, bool> > rightExpression = right.ToExpression(); BinaryExpression orExpression = Expression.OrElse(leftExpression.Body, rightExpression.Body); return(Expression.Lambda <Func <T, bool> >(orExpression, leftExpression.Parameters.First())); }
public override Expression <Func <T, bool> > ToExpression() { Expression <Func <T, bool> > leftExpression = left.ToExpression(); Expression <Func <T, bool> > rightExpression = right.ToExpression(); ParameterExpression param = Expression.Parameter(typeof(T), "x"); BinaryExpression andExpression = Expression.AndAlso(leftExpression.Body, rightExpression.Body); return(Expression.Lambda <Func <T, bool> >(andExpression, leftExpression.Parameters.First())); }
public static Expression <Func <ExpressionTreeEF.User, bool> > UserSearch(List <SearchCriteria> criteria) { Specification <ExpressionTreeEF.User> includes = Specification <ExpressionTreeEF.User> .All; foreach (var item in criteria) { switch (item.Field) { case "FirstName": { if (item.Operation == OperationsEnum.ALL) { includes = includes.And(new UserFirstNameSpecification(item.Value)); } else if (item.Operation == OperationsEnum.AND) { includes = includes.And(new UserFirstNameSpecification(item.Value)); } else { includes = includes.Or(new UserFirstNameSpecification(item.Value)); } } break; case "LastName": { if (item.Operation == OperationsEnum.ALL) { includes = includes.And(new UserLastNameSpecification(item.Value)); } else if (item.Operation == OperationsEnum.AND) { includes = includes.And(new UserLastNameSpecification(item.Value)); } else { includes = includes.Or(new UserLastNameSpecification(item.Value)); } } break; default: throw new Exception(); } } return(includes.ToExpression()); }