Session.GetObjectByKeyAsync<ClassType>(Object, CancellationToken) Method
Asynchronously returns a persistent object that has the specified key property value. The persistent object’s type is set by the generic type parameter.
Namespace: DevExpress.Xpo
Assembly: DevExpress.Xpo.v25.2.dll
NuGet Package: DevExpress.Xpo
Declaration
Parameters
| Name | Type | Description |
|---|---|---|
| id | Object | An object that represents the persistent object’s key property value. |
Optional Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| cancellationToken | CancellationToken | null | A CancellationToken object that delivers a cancellation notice to the running operation. |
Type Parameters
| Name | Description |
|---|---|
| ClassType | A type of objects to search for. |
Returns
| Type | Description |
|---|---|
| Task<ClassType> | A Task that returns a persistent object. This persistent object has the specified key property value and a type specified by the generic type parameter. The task returns null if no objects are found. |
Remarks
Below is an example of using the GetObjectByKeyAsync<ClassType> method. Here, the session is the Session instance.
using System.Threading;
using DevExpress.Xpo;
// ...
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken cancellationToken = source.Token;
Person personToDelete = await session.GetObjectByKeyAsync<Person>(152, cancellationToken);
session.Delete(personToDelete);
The GetObjectByKeyAsync<ClassType> method searches the memory for the object that has the key property value. If such an object is found, it is not reloaded. To get the up-to-date object from the storage, use the overloaded Session.GetObjectByKeyAsync method with the alwaysGetFromDataStore parameter set to true.
Note
The GetObjectByKeyAsync<ClassType> method does not find objects until they are saved to a data store.
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetObjectByKeyAsync<ClassType>(Object, CancellationToken) 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.