Small and simple API which allows you to easily write CAML queries, in a declarative way.

Example:

var and = 
    CamlLogicalJoin.And(
        CamlOperator.Contains("HairColors", CamlFieldType.Text, "brown"),
        CamlOperator.BeginsWith("Name", CamlFieldType.Text, "John"),
        CamlOperator.GreaterThanOrEqualTo("Age", CamlFieldType.Integer, 21),
        CamlLogicalJoin.Or(
            CamlOperator.IsNotNull("Counter"),
            CamlOperator.IsNull("Flag")));

var queryCaml = 
    CamlQuery.BuildQuery(and)
        .OrderBy("Country", CamlOrderByFieldOrder.Ascending)
        .OrderBy("Age", CamlOrderByFieldOrder.Descending)
        .GroupBy("Address")
        .GetQueryClause();

Output:

<Query>
   <Where>
      <And>
         <Contains>
            <FieldRef Name='HairColors' />
            <Value Type='Text'>brown</Value>
         </Contains>
         <And>
            <BeginsWith>
               <FieldRef Name='Name' />
               <Value Type='Text'>John</Value>
            </BeginsWith>
            <And>
               <Geq>
                  <FieldRef Name='Age' />
                  <Value Type='Integer'>21</Value>
               </Geq>
               <Or>
                  <IsNotNull>
                     <FieldRef Name='Counter' />
                  </IsNotNull>
                  <IsNull>
                     <FieldRef Name='Flag' />
                  </IsNull>
               </Or>
            </And>
         </And>
      </And>
      <GroupBy>
         <FieldRef Name='Address' />
      </GroupBy>
      <OrderBy>
         <FieldRef Name='Country' />
         <FieldRef Name='Age' Ascending='False' />
      </OrderBy>
   </Where>
</Query>

Last edited Dec 8, 2012 at 2:42 AM by JoaoPe, version 12