Table of Contents

Method SingleOrDefaultAsync

Namespace
Open.Database.Extensions
Assembly
Open.Database.Extensions.Core.dll

SingleOrDefaultAsync<T>(IMappedQuery<T>, CancellationToken)

Asynchronously reads the only mapped row.

public static ValueTask<T?> SingleOrDefaultAsync<T>(this IMappedQuery<T> query, CancellationToken cancellationToken = default)

Parameters

query IMappedQuery<T>

The query to execute.

cancellationToken CancellationToken

Cancels the operation. When it cannot be canceled, the cancellation token set on the underlying command applies.

Returns

ValueTask<T>

A task that produces the single row, or default if the query returns no rows.

Type Parameters

T

The type each row is mapped to.

Exceptions

OperationCanceledException

The operation was canceled.

InvalidOperationException

The query returns more than one row.

See Also