AggregateOperand.Sum(CriteriaOperator) Method
Creates a new AggregateOperand which returns the sum of values calculated by the given aggregate expression. This expression is evaluated against elements of the AggregateOperand.CollectionProperty that match the specified AggregateOperand.Condition.
Namespace: DevExpress.Data.Filtering
Assembly: DevExpress.Data.v24.1.dll
NuGet Package: DevExpress.Data
Declaration
Parameters
Name | Type | Description |
---|---|---|
aggregatedExpression | CriteriaOperator | A CriteriaOperator object which specifies the aggregate expression. |
Returns
Type | Description |
---|---|
AggregateOperand | An AggregateOperand object which calculates an aggregate expression. |
Example
Example 1
Get the sum of values from a whole collection
Expression:
CriteriaOperator.FromLambda<Order, int>(o => o.OrderItems.Sum(oi => oi.ItemPrice));
Input:
Order | OrderItemName | ItemPrice |
---|---|---|
Order0 | ||
OrderItem1 | 10 | |
OrderItem2 | 20 |
The result: 30
Example 2
Get the sum of values from a filtered collection.
Expression:
CriteriaOperator.FromLambda<Order, int>(o => o.OrderItems.Where(oi => oi.IsAvailable == true).Sum(oi => oi.ItemPrice)); ;
Input:
Order | OrderItemName | ItemPrice | IsAvailable |
---|---|---|---|
Order0 | |||
OrderItem1 | 10 | False | |
OrderItem2 | 20 | False | |
OrderItem2 | 30 | True | |
OrderItem2 | 40 | True |
The result: 70