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

Multiple Order By statements

Aug 31, 2010 at 5:17 PM

I've used a list of expressions to pass into the WhereAny statement, but how would you use multiple order bys?

Developer
Aug 31, 2010 at 8:18 PM

Such functionality is already present (so you don't have to download the new version).

The following example

var ids = new List<int> {1, 2, 3};
var expressions = new List<Expression<Func<SPListItem, bool>>>();
foreach (var i in ids) { expressions.Add(x => (int)x["ID"] == i); }
var caml = Camlex.Query().WhereAll(expressions).OrderBy(x => new[] { x["Field1"], x["Field12"] } ).ToString();

should produce the output like:

<Where>
  <And>
    <And>
      <Eq>
        <FieldRef Name="ID" />
        <Value Type="Integer">3</Value>
      </Eq>
      <Eq>
        <FieldRef Name="ID" />
        <Value Type="Integer">3</Value>
      </Eq>
    </And>
    <Eq>
      <FieldRef Name="ID" />
      <Value Type="Integer">3</Value>
    </Eq>
  </And>
</Where>
<OrderBy>
  <FieldRef Name="Field1" />
  <FieldRef Name="Field12" />
</OrderBy>
I hope it helps!