Adding expressions to dynamically built multiple in clauses

Jan 29, 2013 at 9:50 PM

Hi 

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?

Regards

Rajesh

 

 

Coordinator
Jan 30, 2013 at 8: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);
    exprs.Add(whereExpr);
    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 31, 2013 at 12:08 AM
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?

Thanks
Coordinator
Jan 31, 2013 at 8:19 AM
Edited Jan 31, 2013 at 8:19 AM
hi,
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 11: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:
<In>
<FieldRef Name="Location" />
<Values>
<Value Type="MultiChoice">UK</Value>
<Value Type="MultiChoice">USA</Value>
</Values>
</In>

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.

Regards

Rajesh
Feb 1, 2013 at 9:55 PM
Hi Sadomovalex

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

Regards

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