Skip to main content
A newer version of this page is available. .

XPQueryExtensions.SingleOrDefaultAsync<T>(IQueryable<T>, Expression<Func<T, Boolean>>, CancellationToken) Method

Asynchronously gets the object from a selection if only one object in the selection meets the specified requirements. If the selection is empty, returns a default value for <T>. If the selection has more than one of such elements, throws an exception.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v18.2.dll

Declaration

public static Task<T> SingleOrDefaultAsync<T>(
    this IQueryable<T> query,
    Expression<Func<T, bool>> predicate,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

Name Type Description
query IQueryable<T>

An XPQuery<T> that specifies a selection of persistent objects.

predicate Expression<Func<T, Boolean>>

An expression which determines requirements the persistent object needs to meet.

Optional Parameters

Name Type Default Description
cancellationToken CancellationToken *null*

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

Type Parameters

Name
T

Returns

Type Description
Task<T>

A Task that returns that returns one object if this is the only object in a selection to meet the specified requirements.

See Also