Skip to main content
.NET Framework 4.6.2+

Session.FindObjectAsync<ClassType>(CriteriaOperator, CancellationToken) Method

Asynchronously searches for the first object that matches the specified criteria. This object’s type is designated by the specified generic parameter.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v24.2.dll

Declaration

public Task<ClassType> FindObjectAsync<ClassType>(
    CriteriaOperator criteria,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

Name Type Description
criteria CriteriaOperator

A CriteriaOperator descendant which represents the criteria the persistent object must match.

Optional Parameters

Name Type Default Description
cancellationToken CancellationToken null

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

Type Parameters

Name
ClassType

Returns

Type Description
Task<ClassType>

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

Remarks

Below is an example of using the FindObjectAsync<ClassType> method. Here, session is the Session instance.

using System.Threading;
using DevExpress.Data.Filtering;
using DevExpress.Xpo;
// ...
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken cancellationToken = source.Token;
Person personToUpdate = 
    await session.FindObjectAsync<Person>(CriteriaOperator.Parse("Name='Michael Suyama'"), cancellationToken);
if(personToUpdate != null) {
    personToUpdate.Birthday = new DateTime(1986, 10, 31);
    session.Save(personToUpdate);
}

Criteria are evaluated on the data store side. Objects created within a transaction (Cache) are not processed by the criteria. Objects modified within a transaction are not processed. Instead, their images, stored in the data store, are processed by the criteria.

To specify how filter criteria are evaluated within a transaction, use the overloaded FindObjectAsync method that takes the PersistentCriteriaEvaluationBehavior value as a parameter.

Persistent objects that are marked as deleted in the database (see Deferred and Immediate Object Deletion) are not included in the search.

See Also