How to aggregation with Camlex

May 20, 2011 at 12: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"],

  false 

, 1).ToString();

SPListItemCollection

items = list.GetItems(query);

 

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

PS Sory for my english

Developer
May 20, 2011 at 8: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.

http://stackoverflow.com/questions/1069494/caml-groupby-usage-when-querying-a-list-using-the-spquery-or-spsitedataquery-obje