Thursday, October 13, 2016

Camlex 4.2 and Camlex.Client 2.2 are released

I’m pleasant to announce that today new version of Camlex 4.2 and Camlex.Client 2.2 (Camlex version for client object model) were released. Camlex is free open source library for Sharepoint developers which simplifies creation of CAML queries via using of C# lambda expressions. Camlex is especially useful for creating of dynamic CAML queries when amount of conditions is not known in compile time.

Before to describe changes I need to say that credits of this release go to MarTiX codeplex user which implemented most of necessary functionality and submitted pull request to the Camlex. This is not first time when developers contribute to Camlex project and from my point of view this is great example of open source community cooperation. Thank you MarTiX for your contribution!

In version 4.2/2.2 support for LookupMulti field type was added. Now it became possible to create CAML queries which contain LookupMulti with possibility to add LookupId=”True” attribute to FieldRef like in the following example:

   1: var caml =
   2:     Camlex.Query()
   3:         .Where(x => x["Title"] > (DataTypes.LookupMultiId)"5" &&
   4:             x["Author"] == (DataTypes.LookupMultiValue)"Martin").ToString();

In result we will get the following CAML query:

   1: <Where>
   2:   <And>
   3:     <Gt>
   4:       <FieldRef Name="Title" LookupId="True" />
   5:       <Value Type="LookupMulti">5</Value>
   6:     </Gt>
   7:     <Eq>
   8:       <FieldRef Name="Author" />
   9:       <Value Type="LookupMulti">Martin</Value>
  10:     </Eq>
  11:   </And>
  12: </Where>

As usual code is available in Download section on Codepex and in Nuget:

Install-Package Camlex.NET.dll

or

Install-Package Camlex.Client.dll

There were several requests for this feature on Camlex project hosting site on Codeplex, so I hope that with new version of Camlex developers will produce more efficient code.

4 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hello, Alexey:)

    Is it select ListItems where Author exact "Martin" ? (or where Lookup contains Martin)

    ReplyDelete
  3. Shm, LookupMulti fields works with Eq operator not in the same way as other fields. E.g. check https://naimmurati.wordpress.com/2013/12/03/multi-lookup-fields-in-caml-queries-eq-vs-contains/. As described in this example Eq operator works using "contains" semantic, but there LookupId="TRUE" is specified. In our example there is no LookupId="TRUE" attribute for Author field, so in order to be sure I would test it on real lists.

    ReplyDelete
  4. Note that support of LookupMulti fields also allow to query against UserMulti fields using Eq operator which has different semantic when it is used with LookupMulti field types: http://sadomovalex.blogspot.com/2018/12/sharepoint-caml-query-against-usermulti.html

    ReplyDelete