Method ReadAsync
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
ReadAsync<T>(IMappedQuery<T>, Func<IAsyncEnumerable<T>, ValueTask>, CancellationToken)
Asynchronously executes the query and passes the mapped rows to handler as they are read. Use this overload when the handler does not need the cancellation token.
public static ValueTask ReadAsync<T>(this IMappedQuery<T> query, Func<IAsyncEnumerable<T>, ValueTask> handler, CancellationToken cancellationToken = default)
Parameters
queryIMappedQuery<T>The query to execute.
handlerFunc<IAsyncEnumerable<T>, ValueTask>Receives a forward-only asynchronous sequence of mapped rows. Enumerate it inside the handler; it is not valid after the handler returns.
cancellationTokenCancellationTokenCancels the operation. When it cannot be canceled, the cancellation token set on the underlying command applies.
Returns
- ValueTask
A task that completes after the handler has completed and the connection has been released.
Type Parameters
TThe type each row is mapped to.
Exceptions
- ArgumentNullException
handleris null.- OperationCanceledException
The operation was canceled.
- See Also
ReadAsync<T, TResult>(IMappedQuery<T>, Func<IAsyncEnumerable<T>, ValueTask<TResult>>, CancellationToken)
Asynchronously executes the query, passes the mapped rows to handler as they are read, and returns the handler's result. Use this overload when the handler does not need the cancellation token.
public static ValueTask<TResult> ReadAsync<T, TResult>(this IMappedQuery<T> query, Func<IAsyncEnumerable<T>, ValueTask<TResult>> handler, CancellationToken cancellationToken = default)
Parameters
queryIMappedQuery<T>The query to execute.
handlerFunc<IAsyncEnumerable<T>, ValueTask<TResult>>Receives a forward-only asynchronous sequence of mapped rows. Enumerate it inside the handler; it is not valid after the handler returns.
cancellationTokenCancellationTokenCancels the operation. When it cannot be canceled, the cancellation token set on the underlying command applies.
Returns
- ValueTask<TResult>
A task that produces the value returned by
handlerafter the connection has been released.
Type Parameters
TThe type each row is mapped to.
TResultThe type returned by the handler.
Exceptions
- ArgumentNullException
handleris null.- OperationCanceledException
The operation was canceled.
- See Also
-
ReadAsync<TResult>(Func<IAsyncEnumerable<T>, CancellationToken, ValueTask<TResult>>, CancellationToken)
ReadAsync<T>(IMappedQuery<T>, CancellationToken, Func<IAsyncEnumerable<T>, ValueTask>)
Asynchronously executes the query and passes the mapped rows to handler. The cancellation token comes first so the handler can be written as a trailing lambda.
public static ValueTask ReadAsync<T>(this IMappedQuery<T> query, CancellationToken cancellationToken, Func<IAsyncEnumerable<T>, ValueTask> handler)
Parameters
queryIMappedQuery<T>The query to execute.
cancellationTokenCancellationTokenCancels the operation. When it cannot be canceled, the cancellation token set on the underlying command applies.
handlerFunc<IAsyncEnumerable<T>, ValueTask>Receives a forward-only asynchronous sequence of mapped rows. Enumerate it inside the handler; it is not valid after the handler returns.
Returns
- ValueTask
A task that completes after the handler has completed and the connection has been released.
Type Parameters
TThe type each row is mapped to.
Exceptions
- ArgumentNullException
handleris null.- OperationCanceledException
The operation was canceled.
- See Also
ReadAsync<T, TResult>(IMappedQuery<T>, CancellationToken, Func<IAsyncEnumerable<T>, ValueTask<TResult>>)
Asynchronously executes the query, passes the mapped rows to handler, and returns the handler's result. The cancellation token comes first so the handler can be written as a trailing lambda.
public static ValueTask<TResult> ReadAsync<T, TResult>(this IMappedQuery<T> query, CancellationToken cancellationToken, Func<IAsyncEnumerable<T>, ValueTask<TResult>> handler)
Parameters
queryIMappedQuery<T>The query to execute.
cancellationTokenCancellationTokenCancels the operation. When it cannot be canceled, the cancellation token set on the underlying command applies.
handlerFunc<IAsyncEnumerable<T>, ValueTask<TResult>>Receives a forward-only asynchronous sequence of mapped rows. Enumerate it inside the handler; it is not valid after the handler returns.
Returns
- ValueTask<TResult>
A task that produces the value returned by
handlerafter the connection has been released.
Type Parameters
TThe type each row is mapped to.
TResultThe type returned by the handler.
Exceptions
- ArgumentNullException
handleris null.- OperationCanceledException
The operation was canceled.
- See Also
-
ReadAsync<TResult>(Func<IAsyncEnumerable<T>, CancellationToken, ValueTask<TResult>>, CancellationToken)
ReadAsync<T>(IMappedQuery<T>, CancellationToken, Func<IAsyncEnumerable<T>, CancellationToken, ValueTask>)
Asynchronously executes the query and passes the mapped rows to handler together with the cancellation token in effect. The cancellation token comes first so the handler can be written as a trailing lambda.
public static ValueTask ReadAsync<T>(this IMappedQuery<T> query, CancellationToken cancellationToken, Func<IAsyncEnumerable<T>, CancellationToken, ValueTask> handler)
Parameters
queryIMappedQuery<T>The query to execute.
cancellationTokenCancellationTokenCancels the operation. When it cannot be canceled, the cancellation token set on the underlying command applies.
handlerFunc<IAsyncEnumerable<T>, CancellationToken, ValueTask>Receives a forward-only asynchronous sequence of mapped rows and the cancellation token in effect. Enumerate it inside the handler; it is not valid after the handler returns.
Returns
- ValueTask
A task that completes after the handler has completed and the connection has been released.
Type Parameters
TThe type each row is mapped to.
Exceptions
- OperationCanceledException
The operation was canceled.
- See Also
ReadAsync<T, TResult>(IMappedQuery<T>, CancellationToken, Func<IAsyncEnumerable<T>, CancellationToken, ValueTask<TResult>>)
Asynchronously executes the query, passes the mapped rows to handler together with the cancellation token in effect, and returns the handler's result. The cancellation token comes first so the handler can be written as a trailing lambda.
public static ValueTask<TResult> ReadAsync<T, TResult>(this IMappedQuery<T> query, CancellationToken cancellationToken, Func<IAsyncEnumerable<T>, CancellationToken, ValueTask<TResult>> handler)
Parameters
queryIMappedQuery<T>The query to execute.
cancellationTokenCancellationTokenCancels the operation. When it cannot be canceled, the cancellation token set on the underlying command applies.
handlerFunc<IAsyncEnumerable<T>, CancellationToken, ValueTask<TResult>>Receives a forward-only asynchronous sequence of mapped rows and the cancellation token in effect. Enumerate it inside the handler; it is not valid after the handler returns.
Returns
- ValueTask<TResult>
A task that produces the value returned by
handlerafter the connection has been released.
Type Parameters
TThe type each row is mapped to.
TResultThe type returned by the handler.
Exceptions
- OperationCanceledException
The operation was canceled.
- See Also
-
ReadAsync<TResult>(Func<IAsyncEnumerable<T>, CancellationToken, ValueTask<TResult>>, CancellationToken)