Today I’ve released new versions of the Camlex.Net open source project: Camlex.Net 3.4 (basic Camlex for Sharepoint object model) and Camlex.Client 1.2 (Camlex for client object model). Both libraries are also available in NuGet gallery. In order to add them to your project execute the following commands in VS Package manager:
Interesting that it was the 1st release which contains pull request from another user’s fork. In both branches the following new features were added:
1. Join several string conditions into single query
Now it is possible to pass array of string conditions for CAML query. Camlex will join them and will build correct CAML tree. This feature will be useful if you have some other tools or libraries which work with string queries, and would like to simplify joining of these conditions. For example if we have 3 following conditions:
and want to create common query which will return all items which have all conditions met, i.e. Field1 = 1 AND Field2 = 2 AND Field3 = 3, then we can write:
and it will produce the common query:
As you can see Camlex created correct result conditions tree automatically. By the same way you may create query which will return items which have at least one condition met, using WhereAny method (it will use Or instead of And).
2. Support for native double type
Prior to 3.4 version (and 1.2 client version) in order to create queries with Number data type, you needed to use string-based syntax:
which will produce the following CAML:
It is called string-based, because rvalue is represented by string, which is casted to the CAML datatype (DataTypes.Number in the example above). We introduced string-based syntax, because there is no 1 to 1 mapping between C# types and CAML types (e.g. User or WorkflowStatus CAML types). But there are several types which exist both in CAML and in C#: int and Integer, string and Text, DateTime and DateTime. Now double C# type is mapped to Number CAML type. So it is possible to rewrite the above query using shorter version:
As you can see now rvalue is represented by real C# double which is more simpler and intuitive.
This change is also first change which was added from fork of another user (not Camlex developer) with nickname Shapel who sent pull request to Camlex using Codeplex functionality. So I would like to thank Shapel for this contribution and remind that Camlex is free open source project which is open for your contribution. So please fell free to create your forks and send pull requests. It will help to make Camlex more valuable for our every day work.