Expression VisitSelect(Expression source, Expression selectExpression) { var lambda = selectExpression.GetLambda(); if (lambda.Parameters.Count != 1) throw new NotSupportedException("Select method with T parameter is supported, additional parameters like index are not"); var selectBody = lambda.Body; if (selectBody is MemberExpression) RebindPropertiesAndElasticFields(selectBody); if (selectBody is NewExpression) RebindSelectBody(selectBody, ((NewExpression)selectBody).Arguments, lambda.Parameters); if (selectBody is MethodCallExpression) RebindSelectBody(selectBody, ((MethodCallExpression)selectBody).Arguments, lambda.Parameters); finalItemType = selectBody.Type; return Visit(source); }
Expression VisitWhere(Expression source, Expression lambdaPredicate) { var lambda = lambdaPredicate.GetLambda(); var criteriaExpression = lambda.Body as CriteriaExpression ?? BooleanMemberAccessBecomesEquals(lambda.Body) as CriteriaExpression; if (criteriaExpression == null) throw new NotSupportedException(string.Format("Where expression '{0}' could not be translated", lambda.Body)); searchRequest.Filter = AndCriteria.Combine(searchRequest.Filter, criteriaExpression.Criteria); return Visit(source); }
Expression VisitOrderBy(Expression source, Expression orderByExpression, bool ascending) { var lambda = orderByExpression.GetLambda(); var final = Visit(lambda.Body) as MemberExpression; if (final != null) { var fieldName = Mapping.GetFieldName(SourceType, final); var ignoreUnmapped = final.Type.IsNullable(); // Consider a config switch? searchRequest.SortOptions.Insert(0, new SortOption(fieldName, ascending, ignoreUnmapped)); } return Visit(source); }
Expression VisitQuery(Expression source, Expression predicate) { var lambda = predicate.GetLambda(); var wasWithin = within; within = CriteriaWithin.Query; var body = BooleanMemberAccessBecomesEquals(lambda.Body); var criteriaExpression = body as CriteriaExpression; if (criteriaExpression == null) throw new NotSupportedException(string.Format("Query expression '{0}' could not be translated", body)); searchRequest.Query = AndCriteria.Combine(searchRequest.Query, criteriaExpression.Criteria); within = wasWithin; return Visit(source); }