Skip to main content

AggregateOperand.Single(CriteriaOperator) Method

Creates a new AggregateOperand which returns the single object from the AggregateOperand.CollectionProperty that matches the specified AggregateOperand.Condition. The collection must be empty or contain exactly one object.

Namespace: DevExpress.Data.Filtering

Assembly: DevExpress.Data.v24.1.dll

NuGet Package: DevExpress.Data

Declaration

public AggregateOperand Single(
    CriteriaOperator aggregatedExpression
)

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 a property’s value of a specific element from a child collection

Expression:

CriteriaOperator.FromLambda<Order, string>(o => o.OrderItems.SingleOrDefault(oi => oi.ItemPrice == 40).OrderItemName);
Test

Input:

Order

OrderItemName

ItemPrice

Order0

OrderItem1

30

OrderItem2

40

The result: OrderItem2

Example 2

Get a specific element from a child collection.

Expression:

CriteriaOperator.FromLambda<Order, OrderItem>(o => o.OrderItems.SingleOrDefault(oi => oi.ItemPrice == 40));
Test

Input:

Order

OrderItemId

OrderItemName

ItemPrice

Order0

0

OrderItem1

30

1

OrderItem2

40

The result: 1

Example 3

Get a specific element from a child collection and use it in another expression.

Expression:

CriteriaOperator.FromLambda<OrderItem>(oi => oi.Order == FromLambdaFunctions.FreeJoin<Order>(o => o.OrderItems.Any(oii => oii.ItemPrice == 456)).SingleOrDefault());
Test

Input:

OrderId

Order

OrderItemName

ItemPrice

1

Order0

OrderItem1

1

OrderItem2

456

OrderItem3

3

OrderItem4

4

2

Order1

OrderItem5

30

OrderItem6

40

The result:

OrderItemName

ItemPrice

OrderItem1

1

OrderItem2

456

OrderItem3

3

OrderItem4

4

See Also