Dynamic filtering conditions

Sep 12, 2012 at 2:35 PM
Edited Sep 12, 2012 at 2:44 PM

Hi,

First of all thanks for the library, great piece of work!

But... I am having issues trying to get the dynamic filerting to work.

I have the following:

var query = new SPQuery();
var businessUnitTokens = new String[] { "GGES", "Global Gas, Power and Derivatives", "Oil, LPG & FX Global Functions", "Communications", "Legal" };
var expressions = new List<Expression<Func<SPListItem, Boolean>>>();
expressions.Add(x => (String)x[field1] == item[field1].ToString());

foreach (var businessUnit in businessUnitTokens)
{
	expressions.Add(x => ((String)x[field2]).Contains(businessUnit));
}

query.Query = Camlex.Query()
	.WhereAny(expressions)
	.OrderBy(x => x["Modified"] as Camlex.Desc).ToString();

But I always end up with the following query. I.e. The value of business unit is always Legal!

<Where>
  <Or>
    <Or>
      <Or>
        <Or>
          <Or>
            <Eq>
              <FieldRef Name="Subject" />
              <Value Type="Text">Strategy</Value>
            </Eq>
            <Contains>
              <FieldRef Name="BusinessUnit" />
              <Value Type="Text">Legal</Value>
            </Contains>
          </Or>
          <Contains>
            <FieldRef Name="BusinessUnit" />
            <Value Type="Text">Legal</Value>
          </Contains>
        </Or>
        <Contains>
          <FieldRef Name="BusinessUnit" />
          <Value Type="Text">Legal</Value>
        </Contains>
      </Or>
      <Contains>
        <FieldRef Name="BusinessUnit" />
        <Value Type="Text">Legal</Value>
      </Contains>
    </Or>
    <Contains>
      <FieldRef Name="BusinessUnit" />
      <Value Type="Text">Legal</Value>
    </Contains>
  </Or>
</Where>
<OrderBy>
  <FieldRef Name="Modified" Ascending="False" />
</OrderBy>
Is there something I am doing wrong here? Any help would be much appreciated.
Developer
Sep 12, 2012 at 2:56 PM

Please see previous discussion - http://camlex.codeplex.com/discussions/250635

Sep 12, 2012 at 3:05 PM

awesome!

Thank you.

Coordinator
Sep 12, 2012 at 3:08 PM

this is the most popular question in the discussions :)