Skip to main content

ContainsOperator Class

An operator which checks if a collection contains at least one object matching a specific criteria.

Namespace: DevExpress.Data.Filtering

Assembly: DevExpress.Data.v24.1.dll

NuGet Package: DevExpress.Data

Declaration

public sealed class ContainsOperator :
    AggregateOperand

Remarks

The ContainsOperator operator can be used to filter the contents of the XPCollection.

You can also use the CriteriaOperator.Parse method to create a CriteriaOperator operator for a specific expression.

Tip

You can find examples in the following article: Build Criteria - Cheat Sheet.

Examples

Selects Order objects that contain at least one object in their OrderItems collection with the OrderPrice property set to 44.

Expression:

// There is no LINQ expression that generates the ContainsOperator you can solve this task using the following expression

CriteriaOperator.FromLambda<Order>(o => o.OrderItems.Any(oi => oi.ItemPrice == 44));
Test

Input:

Order

OrderItem

ItemPrice

Order0

Item0-0

10

Item0-1

20

Order1

Item1-0

30

Item1-1

44

The result:

Order

Order1


Selects Orders with Price equal to 99 and has OrderItems with ItemPrice equal to 10:

Expression:

CriteriaOperator.FromLambda<Order>(o => o.OrderItems.Any(oi => oi.ItemPrice == 10) && o.Price == 99);
Test

Input:

OrderName

Price

OrderItemName

ItemPrice

Order0

99

OrderItem00

2

OrderItem01

4

Order1

99

OrderItem10

5

OrderItem11

10

The result:

OrderName

Order1


Selects Orders with OrderItems that has Company with CompanyName equal to ‘Company1’:

Expression:

CriteriaOperator.FromLambda<Order>(o => o.OrderItems.Any(oi => oi.Company.CompanyName == "Company1"));
Test

Input:

OrderName

OrderItemName

CompanyName

Order0

OrderItem00

Company0

Company2

Order1

OrderItem10

Company1

Company3

The result:

OrderName

Order1

Inheritance

See Also