Session.GetObjectByKeyAsync(Type, Object, CancellationToken) Method
Asynchronously returns a persistent object that has the specified key property value.
Namespace: DevExpress.Xpo
Assembly: DevExpress.Xpo.v24.2.dll
NuGet Package: DevExpress.Xpo
#Declaration
public Task<object> GetObjectByKeyAsync(
Type classType,
object id,
CancellationToken cancellationToken = default(CancellationToken)
)
#Parameters
Name | Type | Description |
---|---|---|
class |
Type | A Type object which represents the type of objects to search for. |
id | Object | An object that represents the persistent object’s key property value. |
#Optional Parameters
Name | Type | Default | Description |
---|---|---|---|
cancellation |
Cancellation |
null | A Cancellation |
#Returns
Type | Description |
---|---|
Task<Object> | A Task that returns a persistent object. This persistent object has the specified key property value. The task returns null if no objects are found. |
#Remarks
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, cancellationToken);
session.Delete(personToDelete);
The GetObjectByKeyAsync method searches the memory for the object with the key property value. If such an object is found, it is not reloaded.