Skip to main content
.NET 6.0+

Session.Evaluate(XPClassInfo, CriteriaOperator, CriteriaOperator) Method

Evaluates the specified expression for objects of the specified type.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v23.2.dll

NuGet Package: DevExpress.Xpo

Declaration

public object Evaluate(
    XPClassInfo classInfo,
    CriteriaOperator expression,
    CriteriaOperator criteria
)

Parameters

Name Type Description
classInfo XPClassInfo

An XPClassInfo object that identifies the type of objects against which the expression is 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 are 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 example, you can use the Count() function to calculate the number of objects specified.

The criteria parameter specifies the criteria used for object selection. The expression is evaluated only against the objects that match these criteria. Set the criteria to null (Nothing in VB.NET) to evaluate the expression against all the objects in the data store.

To construct the expression and criteria, use the static CriteriaOperator.Parse method. The method takes a string representation of the required expression and retrieves a 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,
  • calculate the number of all Person objects.

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 without loading data items from the data base server.
object count = session1.Evaluate(typeof(Person), CriteriaOperator.Parse("Count()"),
    CriteriaOperator.Parse("IsMale = true"));

// Calculate the number of all persons without loading all data items from the data base server.
object countAll = session1.Evaluate(typeof(Person), CriteriaOperator.Parse("Count()"),
    null);

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Evaluate(XPClassInfo, 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