Method SingleAsync
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
SingleAsync(CancellationToken)
Asynchronously reads the only mapped row; throws if the query returns no rows or more than one.
public ValueTask<T> SingleAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancels 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 single row.
Remarks
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.
The more-than-one error is thrown at the second row, before the later result sets are read, so it is never replaced by a later failure.
Exceptions
- OperationCanceledException
The operation was canceled.
- InvalidOperationException
The query returns no rows, or more than one row.
- See Also
-
Single<T>(MappedQuery<T>)