The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.

Filtering Basics

Querying a data store allows you to retrieve data that matches specific criteria and store it within a temporary data store (e.g. XPCollection) for further review and evaluation. Data that is stored in a temporary data store can also be filtered.

In both instances, a filter criteria must be applied. The criteria represents the logical expression that is used as a data filter. Each temporary data store has two properties that are used to filter objects on the data store and client sides. These properties are listed and described below:

The following example demonstrates how to define a simple criteria to query the data store for those customers who are older than 40.


using DevExpress.Xpo;
using DevExpress.Data.Filtering;

class Customer : XPObject {
    public string Name;
    public int Age;
}

...
// Specify the filter criteria.
BinaryOperator filterCriteria = new BinaryOperator("Age", 40, BinaryOperatorType.Greater);

// Retrieve only those customers who are older than 40.
XPCollection collection = new XPCollection(typeof(Customer), filterCriteria);

The image below shows the result:

QueryingFiltering1

The retrieved collection of persistent objects can also be filtered. Use its XPBaseCollection.Filter property to apply the desired filter. In the example below, the collection is filtered to return only those customers who are older than 42 but younger than 50.


collection.Filter = new BetweenOperator("Age", 42, 50);

The image below shows the result:

QueryingFiltering2

 

Note

Unsaved objects are not loaded into an XPCollection.

XPO queries the database and retrieves values. Then it instantiates persistent objects from the query result and adds these objects to the XPCollection. Before an object is instantiated, XPO searches for it in the cache by its Oid. If the object is found, its properties are refreshed and it is then added to the collection. Unsaved objects don't have corresponding records in the database and therefore they don't fall into the query result and thus aren't added to the collection. This is the expected result. Objects must be saved to be included in the query results.