This project has moved and is read-only. For the latest updates, please go here.

How to aggregation with Camlex

May 20, 2011 at 1:59 PM

Hello All!

Please help me. I have custom list TestList with fields: Title (text) and Value (Number).

I want get somethink like  

Select Title, Value=Sum(Value) from TestList group by Title

 My code

SPContext ctx = SPContext.Current;

SPList list = ctx.Site.RootWeb.Lists.TryGetList("TestList");

if (list == nullreturn;


SPQuery query = new SPQuery();

query.ViewFields = Camlex.Query().

ViewFields(x => new[] { x["Title"], x["Value"


query.Query = Camlex.Query().GroupBy(x => x["Title"],


, 1).ToString();


items = list.GetItems(query);


But, I have not sum and get all rows without grouping. Where I wrong?

PS Sory for my english

May 20, 2011 at 9:23 PM

Hi, vasire!

GroupBy in SPQuery has different meaning than in SQL language. It is more like sorting.

For example, when you specify in a list view settings, that, for example, there is a grouping by Title column, then in UI you will see ALL rows.

The only difference, that rows with the same Title are located in one area.

So the functionality you wanted is not supported by CAML, unfortunately.