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

XPObjectSpace.EvaluateAsync(Type, CriteriaOperator, CriteriaOperator, CancellationToken) Method

Asynchronously evaluates the specified criteria for business objects of the given type.

Namespace: DevExpress.ExpressApp.Xpo

Assembly: DevExpress.ExpressApp.Xpo.v19.2.dll

Declaration

public Task<object> EvaluateAsync(
    Type objectType,
    CriteriaOperator expression,
    CriteriaOperator criteria,
    CancellationToken cancellationToken = default(CancellationToken)
)

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.

Optional Parameters

Name Type Default Description
cancellationToken CancellationToken *null*

A CancellationToken object that delivers a cancellation notice to the running operation.

Returns

Type Description
Task<Object>

A Task that returns an object. This object represents the evaluated value. null (Nothing in Visual Basic) if no persistent object is found that matches the criteria.

Remarks

You can use the static CriteriaOperator.Parse method to construct the expression and criteria. This method takes a string representation of the required expression and creates the CriteriaOperator object that corresponds to this expression.

The following code demonstrates how to use this method in a View Controller to evaluate contact’s assigned tasks.

using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Xpo;
using System;
using System.Threading;
// ...
public class AsyncTasksCountController : ObjectViewController<DetailView, Contact> {
    public AsyncTasksCountController() : base() {
        SimpleAction EvaluateTasksCountAction = new SimpleAction(this, "Assigned tasks count", "Edit");
        EvaluateTasksCountAction.SelectionDependencyType = SelectionDependencyType.RequireSingleObject;
        EvaluateTasksCountAction.Execute += EvaluateTasksCountAction_Execute;
    }
    async private void EvaluateTasksCountAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
        CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
        Guid currentContactOid = ViewCurrentObject.Oid;
        XPObjectSpace taskObjectSpace = (XPObjectSpace)Application.CreateObjectSpace(typeof(DemoTask));
        object tasksCount =
            await taskObjectSpace.EvaluateAsync(
            typeof(DemoTask), CriteriaOperator.Parse("Count()"),
            CriteriaOperator.Parse(string.Format("[AssignedTo.Oid] = '{0}'", currentContactOid)),
            cancellationTokenSource.Token);
        if (tasksCount != null) {
            ViewCurrentObject.AssignedTasksCount = (int)tasksCount;
        }
    }
}

In the current example, the cancellationToken parameter is used for demonstration purposes. You can skip it or use to cancel an asynchronous operation as shown in the CancellationToken topic.

See Also