GROUPPARTITION

Returns a collection of argument values that are projected off the current group partition to which the aggregate is related. The GroupPartition aggregate is a group-based aggregate and has no collection-based form.

Syntax

GROUPPARTITION(expression )

Arguments

expression Any Entity SQL expression.

Remarks

The following query produces a list of category and a collection of product quantities per each category:
var esql = @"select Category, GroupPartition(p) as Products
                from Products as p 
                group by p.Category";
var items = db.CreateQuery<IDataRecord>(esql);
foreach (var item in items)
{
    foreach (Product p in (IEnumerable<Product>)item["Products"])
    {
        Console.WriteLine(p.ProductName);
    }
}
The following query produces a list of category and sumary the product UnitPrices per each category:
var esql = @"select Category, sum(GroupPartition(p.UnitPrice)) as PriceSum
             from Products as p 
             group by p.Category";
var items = db.CreateQuery<IDataRecord>(esql);
foreach (var item in items)
{
    Console.WriteLine(item["PriceSum"]);
}

Last edited Mar 9, 2013 at 6:56 AM by ansiboy, version 2

Comments

No comments yet.