CSC510224. Camlex query multiple WHERE are not supported.


Currently if several Where... methods (Where, WhereAny or WhereAll) are used in the single call chain, only the last method is actually applied
var expressions = new List<Expression<Func<SPListItem, bool>>>(3);
if (typesFilter.Length != 4)
   for (int i = 0; i < typesFilter.Length; i++)
      var ind = i;
      expressions.Add(x => (string)x[adsOnjList.Fields["Field"].Id] == typesFilter[ind]);
   camlexQuery = Camlex.Query();

camlexQuery = Camlex.Query().WhereAny(expressions).Where(x => x[adsOnjList.Fields["Field2"].Id] == (DataTypes.LookupId)ownerId.ToString());
query.Query = camlexQuery.OrderBy(z => z[SPBuiltInFieldId.Title]).ToString();


In this case, you have to use "CamlexNET.Impl.Helpers.ExpressionsHelper" public class. This class combines many expressions into single one with AND or OR logic. WhereAll and WhereAny methods of Query class are implemented in simple manner:
public IQuery WhereAll(IEnumerable<Expression<Func<SPListItem, bool>>> expressions)
    var combinedExpression = ExpressionsHelper.CombineAnd(expressions);
    return this.Where(combinedExpression);

public IQuery WhereAny(IEnumerable<Expression<Func<SPListItem, bool>>> expressions)
    var combinedExpression = ExpressionsHelper.CombineOr(expressions);
    return this.Where(combinedExpression);

So it can give you a clue how to use ExpressionHelper class:
  1. Initially, you combine all expressions (like you do in your example)
  2. Then instead of calling WhereAny method, you call ExpressionHeper.CombineOr() method
  3. It will give you single expression from expressions combined with OR logic
  4. Then create new expression with lookup field
  5. Create an expression list containing 2 expressions - first calculated on step 3 and the second on step 4
  6. Then call ExpressionHeper.CombineAnd() method with the expression list
  7. Then call Query.Where with resulting single expression


Use multiple WHERE in Camlex query

Last edited Mar 12, 2014 at 11:08 AM by dvd73, version 5


No comments yet.