Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

Session.Evaluate(Type, CriteriaOperator, CriteriaOperator) Method

Evaluates the specified expression for objects of the specified type.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v19.1.dll

Declaration

public object Evaluate(
    Type objectType,
    CriteriaOperator expression,
    CriteriaOperator criteria
)

Parameters

Name Type Description
objectType Type

A Type object that identifies the type of objects against which the expression will be evaluated.

expression CriteriaOperator

A CriteriaOperator object that specifies the expression to evaluate.

criteria CriteriaOperator

A CriteriaOperator object that specifies the filter criteria. The objects that match this criteria will be used to evaluate the expression.

Returns

Type Description
Object

The value evaluated.

Remarks

Use this method to evaluate a specific expression against specific objects. In the expression that is specified by the expression parameter you can use the functions specified by the Aggregate enumeration and you can also use a combination of these functions. For instance, by using the “Count()” function it’s possible to calculate the number of objects specified. The criteria parameter specifies the criteria for object selection. The expression will be evaluated only against the objects that match these criteria. Set the criteria to null to evaluate the expression against all the objects in the data store.

To construct expression and criteria the static CriteriaOperator.Parse method can be used which takes a string representation of the required expression and retrieves the CriteriaOperator object that corresponds to this expression.

Example

The following example demonstrates how to calculate the number of Person objects that have their IsMale property set to true.

In this example, the Person class is a custom XPObject that has a Boolean IsMale property. It is assumed that this object belongs to a Session object (session1).

To calculate the number of Person objects in storage, the Session.Evaluate method is used. Its expression parameter specifies the Count function to evaluate, while the criteria parameter specifies a criteria that selects only men. The expression and criteria parameters are constructed using the CriteriaOperator.Parse method.

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

class Person : XPObject {
    //...
    bool isMale;
    public bool IsMale {
        get { return isMale; }
        set { isMale = value; }
    }
}

// Calculate the number of male persons.
object count = session1.Evaluate(typeof(Person), CriteriaOperator.Parse("Count()"),
    CriteriaOperator.Parse("IsMale = true"))

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Evaluate(Type, CriteriaOperator, CriteriaOperator) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also