Table of Contents

Method FirstAsync

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

FirstAsync(CancellationToken)

Asynchronously reads the first mapped row; throws if the query returns no rows.

public ValueTask<T> FirstAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Cancels the call, together with the cancellation token set on the underlying command: either one cancels it, whether it is opening the connection, looking up stored-procedure parameter names, executing or reading.

Returns

ValueTask<T>

A task that produces the first row.

Remarks

Rows after the first are not mapped. Add an ORDER BY to the SQL when "first" must be deterministic.

A row whose value is NULL is still a row, and default is returned for it.

The no-rows error is thrown after the command has been cleaned up: the connection is released and, unless SingleResult() was called, the later result sets have been read through, so a failure in one of them is thrown instead.

Exceptions

OperationCanceledException

The operation was canceled.

InvalidOperationException

The query returns no rows.

See Also