IObjectSpaceAsync.EvaluateAsync(Type, CriteriaOperator, CriteriaOperator, CancellationToken) Method
Asynchronously evaluates the specified criteria for business objects of the given type.
Namespace: DevExpress.ExpressApp
Assembly: DevExpress.ExpressApp.v24.2.dll
NuGet Package: DevExpress.ExpressApp
#Declaration
Task<object> EvaluateAsync(
Type objectType,
CriteriaOperator expression,
CriteriaOperator criteria,
CancellationToken cancellationToken = default(CancellationToken)
)
#Parameters
Name | Type | Description |
---|---|---|
object |
Type | A Type object that identifies the type of objects against which the expression is evaluated. |
expression | Criteria |
A Criteria |
criteria | Criteria |
A Criteria |
#Optional Parameters
Name | Type | Default | Description |
---|---|---|---|
cancellation |
Cancellation |
null | A Cancellation |
#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.