This project has moved. For the latest updates, please go here.

Adding expressions to dynamically built multiple in clauses

Jan 29, 2013 at 8:50 PM


I'm building a query dynamically and there are a few fields which need "In" clause query. Since the Camlex expressions do not support In clause yet, I'm building the in claues separately as a where query. I have a couple of fields on which I'm creating this. I see that WhereAny takes an existing query, but only one query can be passed. Is there a way to pass multiple where caluses to existing expressions?





Jan 30, 2013 at 7:50 PM

Rajesh hi,

currently no, it is not supported. But it is definitely interesting feature and I think it will be useful to add it to one of the next releases. It should not be complicated, so you can do it by yourself if will check implementation of WhereAny method:


public IQuery WhereAny(string existingWhere, IEnumerable<Expression<Func<SPListItem, bool>>> expressions)
    var whereExpr = this.getWhereExpressionFromString(existingWhere);
    var exprs = new List<Expression<Func<SPListItem, bool>>>(expressions);
    return this.WhereAny(exprs);

I.e. if you will have several string queries, you can call getWhereExpressionFromString() method for each, insert them to list and then call original WhereAny() method as in the example above.


Jan 30, 2013 at 11:08 PM
Hi Sadomovalex

Thanks for your reply, unfortunately I didn't follow it properly. I couldn't find the method getWhereExpressionFromString anywhere. I couldn't find this method in Camlex.Query().

Btw, does the above method convert the where clause into an expression if it contains "In" clause?

Jan 31, 2013 at 7:19 AM
Edited Jan 31, 2013 at 7:19 AM
I meant that you can downloaded sources from source code and add this method by yourself. The example which I showed above is from source code.
Currently In operation is not supported.
Jan 31, 2013 at 10:39 PM
Hi Sadomovalex

I thought I would build my in query separately and add to other expressions using WhereAny expression as below

string searchQuery = Camlex.Query().WhereAny(inQuery, searchExpressions).ToString();

When I do this, I get the below exception.

WHERE tag contain element which can't be translated:
<FieldRef Name="Location" />
<Value Type="MultiChoice">UK</Value>
<Value Type="MultiChoice">USA</Value>

at CamlexNET.Impl.ReverseEngeneering.Caml.Factories.ReAnalyzerFromCamlFactory.getAnalyzerForWhere(XElement el)
at CamlexNET.Impl.ReverseEngeneering.Caml.Factories.ReAnalyzerFromCamlFactory.Create(XElement el)
at CamlexNET.Impl.ReverseEngeneering.Caml.Factories.ReTranslatorFromCamlFactory.Create(String input)
at CamlexNET.Impl.Query.getWhereExpressionFromString(String existingWhere)
at CamlexNET.Impl.Query.WhereAny(String existingWhere, IEnumerable`1 expressions)

Looks like the WhereAny can't combine expressions with dynamically built In query. Am I doing anything wrong? Can't I build "In" query this way and combine with other expressions? If this doesn't work then I will have to go with Contains clause which is supported by Camlex. Please confirm.


Feb 1, 2013 at 8:55 PM
Hi Sadomovalex

I have replaced the In clause with multiple equal expressions combined with a WhereAny clause and it is working fine.


Feb 3, 2013 at 5:17 PM
yes, as I wrote above In is not supported yet.