The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

Session.GetObjectByKeyAsync(XPClassInfo, Object, CancellationToken) Method

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

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v19.2.dll

Declaration

public Task<object> GetObjectByKeyAsync(
    XPClassInfo classInfo,
    object id,
    CancellationToken cancellationToken = default(CancellationToken)
)
Public Function GetObjectByKeyAsync(
    classInfo As XPClassInfo,
    id As Object,
    cancellationToken As CancellationToken = Nothing
) As Task(Of Object)
public Task<object> GetObjectByKeyAsync(
    XPClassInfo classInfo,
    object id,
    CancellationToken cancellationToken = default(CancellationToken)
)
Public Function GetObjectByKeyAsync(
    classInfo As XPClassInfo,
    id As Object,
    cancellationToken As CancellationToken = Nothing
) As Task(Of Object)

Parameters

Name Type Description
classInfo XPClassInfo

An XPClassInfo object which contains the metadata information of the class.

id Object

An object which represents the key property's value of the persistent object.

cancellationToken CancellationToken

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

Parameters

Name Type Description
classInfo XPClassInfo

An XPClassInfo object which contains the metadata information of the class.

id Object

An object which represents the key property's value of the persistent object.

cancellationToken CancellationToken

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

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.

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;
using DevExpress.Xpo.Metadata;
// ...
XPClassInfo personClassInfo = session.GetClassInfo(typeof(Person));
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken cancellationToken = source.Token;
Person personToDelete = (Person)await session.GetObjectByKeyAsync(personClassInfo, 152, cancellationToken);
session.Delete(personToDelete);

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

Note

The GetObjectByKeyAsync method does not find objects until they are saved to a data store.

See Also