Table of Contents

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

query IMappedQuery<T>

The query to execute.

handler Func<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.

cancellationToken CancellationToken

Cancels 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

T

The type each row is mapped to.

Exceptions

ArgumentNullException

handler is 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

query IMappedQuery<T>

The query to execute.

handler Func<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.

cancellationToken CancellationToken

Cancels 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 handler after the connection has been released.

Type Parameters

T

The type each row is mapped to.

TResult

The type returned by the handler.

Exceptions

ArgumentNullException

handler is null.

OperationCanceledException

The operation was canceled.

See Also

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

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.

handler Func<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

T

The type each row is mapped to.

Exceptions

ArgumentNullException

handler is 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

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.

handler Func<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 handler after the connection has been released.

Type Parameters

T

The type each row is mapped to.

TResult

The type returned by the handler.

Exceptions

ArgumentNullException

handler is null.

OperationCanceledException

The operation was canceled.

See Also

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

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.

handler Func<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

T

The 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

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.

handler Func<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 handler after the connection has been released.

Type Parameters

T

The type each row is mapped to.

TResult

The type returned by the handler.

Exceptions

OperationCanceledException

The operation was canceled.

See Also