“I had an array with integer values. I need to create query which will return all items which have ID which presents in this array of integers. I.e. I need to join several <FieldRef> with different <Value> via Or operation”.
It is interesting feature and we didn’t address it in the 1st release of Camlex. Nevertheless there is a workaround for this problem which requires additional coding and is not very convenient. But it works.
The general idea is to build expression dynamically and pass it into Camlex. So we have an array of integers:
At first we need to create single expression which will be translated into <Eq> operation in CAML for each id in list, i.e. we need the following CAML for each element of array:
The following code shows how it can be done:
Here we construct expression “(int)x[“ID”] == i” for each i in array of integers. Now we need to combine the list of these expressions using || (OrElse) operation:
Function generateResultOrElseExpression() has the following code:
I.e. it accumulates expressions into prevExpr parameter and recursively calls itself. After that you will have the following CAML query:
As you see it is not so simple to achieve the result. We will try to help developers to solve such problems with less efforts in the next releases of Camlex. I’m not sure about exact view of solution, may be something like this:
What do you think?
And thanks to Olegas for feedback.