.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

Session.GetObjectByKeyAsync(Type, Object, Boolean, CancellationToken) Method

Asynchronously returns a persistent object that has the specified key property value from a data store.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v21.2.dll


public Task<object> GetObjectByKeyAsync(
    Type classType,
    object id,
    bool alwaysGetFromDataStore,
    CancellationToken cancellationToken = default(CancellationToken)


Name Type Description
classType Type

A Type object which represents the type of objects to search for.

id Object

An object which represents the persistent object’s key property value.

alwaysGetFromDataStore Boolean

true, to always reload the persistent object from storage even if it is found in memory; otherwise, false.

Optional Parameters

Name Type Default Description
cancellationToken CancellationToken


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


Type Description

A Task that returns a persistent object from a data store. This persistent object has the specified key property value. The task returns null if no objects are found.


Below is an example of using the GetObjectByKeyAsync method. Here, the session is the Session instance.

using System.Threading;
using DevExpress.Xpo;
// ...
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken cancellationToken = source.Token;
Person personToDelete = 
    (Person)await session.GetObjectByKeyAsync(typeof(Person), 152, true, cancellationToken);

The GetObjectByKeyAsync method searches the memory for the object with the key property value. If such an object is found, it is not reloaded. To get the up-to-date object from the data store, set the alwaysGetFromDataStore parameter to true.

See Also