Method ExecuteReaderAsync
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.MSSqlClient.dll
ExecuteReaderAsync(SqlCommand, Func<SqlDataReader, ValueTask>, CancellationToken)
Asynchronously executes the command and passes the SqlDataReader to the handler.
public static ValueTask ExecuteReaderAsync(this SqlCommand command, Func<SqlDataReader, ValueTask> handler, CancellationToken cancellationToken = default)
Parameters
commandSqlCommandThe command to execute. Its connection is opened if needed and closed again if it was opened here; neither the command nor the connection is disposed.
handlerFunc<SqlDataReader, ValueTask>The function that reads from the reader. Do not let the reader escape it.
cancellationTokenCancellationTokenA token that can cancel opening the connection and executing the command. The default is None.
Returns
- ValueTask
A task that represents the asynchronous operation. It completes after
handlerhas completed and the reader has been disposed.
Remarks
Exceptions from the provider (for example SqlException) propagate unchanged. The reader is disposed, and with it a connection that this method opened, even when the function passed in throws.
Exceptions
- ArgumentNullException
commandorhandleris null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled before or while the connection was being opened or the command executed.
ExecuteReaderAsync(SqlCommand, Func<SqlDataReader, ValueTask>, CommandBehavior, CancellationToken)
Asynchronously executes the command and passes the SqlDataReader to the handler.
public static ValueTask ExecuteReaderAsync(this SqlCommand command, Func<SqlDataReader, ValueTask> handler, CommandBehavior behavior, CancellationToken cancellationToken = default)
Parameters
commandSqlCommandThe command to execute. Its connection is opened if needed and closed again if it was opened here; neither the command nor the connection is disposed.
handlerFunc<SqlDataReader, ValueTask>The function that reads from the reader. Do not let the reader escape it.
behaviorCommandBehaviorThe behavior to use with the data reader. CloseConnection is added when the command opens a closed connection. The default is Default.
cancellationTokenCancellationTokenA token that can cancel opening the connection and executing the command. The default is None.
Returns
- ValueTask
A task that represents the asynchronous operation. It completes after
handlerhas completed and the reader has been disposed.
Remarks
Exceptions from the provider (for example SqlException) propagate unchanged. The reader is disposed, and with it a connection that this method opened, even when the function passed in throws.
Exceptions
- ArgumentNullException
commandorhandleris null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled before or while the connection was being opened or the command executed.
ExecuteReaderAsync(SqlCommand, Action<SqlDataReader>, CancellationToken)
Asynchronously executes the command and passes the SqlDataReader to a synchronous handler.
public static ValueTask ExecuteReaderAsync(this SqlCommand command, Action<SqlDataReader> handler, CancellationToken cancellationToken = default)
Parameters
commandSqlCommandThe command to execute. Its connection is opened if needed and closed again if it was opened here; neither the command nor the connection is disposed.
handlerAction<SqlDataReader>The function that reads from the reader. Do not let the reader escape it.
cancellationTokenCancellationTokenA token that can cancel opening the connection and executing the command. The default is None.
Returns
- ValueTask
A task that represents the asynchronous operation. It completes after
handlerhas completed and the reader has been disposed.
Remarks
Exceptions from the provider (for example SqlException) propagate unchanged. The reader is disposed, and with it a connection that this method opened, even when the function passed in throws.
Exceptions
- ArgumentNullException
commandorhandleris null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled before or while the connection was being opened or the command executed.
ExecuteReaderAsync(SqlCommand, Action<SqlDataReader>, CommandBehavior, CancellationToken)
Asynchronously executes the command and passes the SqlDataReader to a synchronous handler.
public static ValueTask ExecuteReaderAsync(this SqlCommand command, Action<SqlDataReader> handler, CommandBehavior behavior, CancellationToken cancellationToken = default)
Parameters
commandSqlCommandThe command to execute. Its connection is opened if needed and closed again if it was opened here; neither the command nor the connection is disposed.
handlerAction<SqlDataReader>The function that reads from the reader. Do not let the reader escape it.
behaviorCommandBehaviorThe behavior to use with the data reader. CloseConnection is added when the command opens a closed connection. The default is Default.
cancellationTokenCancellationTokenA token that can cancel opening the connection and executing the command. The default is None.
Returns
- ValueTask
A task that represents the asynchronous operation. It completes after
handlerhas completed and the reader has been disposed.
Remarks
Exceptions from the provider (for example SqlException) propagate unchanged. The reader is disposed, and with it a connection that this method opened, even when the function passed in throws.
Exceptions
- ArgumentNullException
commandorhandleris null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled before or while the connection was being opened or the command executed.
ExecuteReaderAsync<T>(SqlCommand, Func<SqlDataReader, T>, CancellationToken)
Asynchronously executes the command and passes the SqlDataReader to the transform function, returning its result.
public static ValueTask<T> ExecuteReaderAsync<T>(this SqlCommand command, Func<SqlDataReader, T> transform, CancellationToken cancellationToken = default)
Parameters
commandSqlCommandThe command to execute. Its connection is opened if needed and closed again if it was opened here; neither the command nor the connection is disposed.
transformFunc<SqlDataReader, T>The function that reads from the reader and produces the result. Do not let the reader escape it.
cancellationTokenCancellationTokenA token that can cancel opening the connection and executing the command. The default is None.
Returns
- ValueTask<T>
A task that represents the asynchronous operation; its result is the value returned by
transform.
Type Parameters
TThe return type of the transform function.
Remarks
Exceptions from the provider (for example SqlException) propagate unchanged. The reader is disposed, and with it a connection that this method opened, even when the function passed in throws.
Exceptions
- ArgumentNullException
commandortransformis null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled before or while the connection was being opened or the command executed.
ExecuteReaderAsync<T>(SqlCommand, Func<SqlDataReader, T>, CommandBehavior, CancellationToken)
Asynchronously executes the command and passes the SqlDataReader to the transform function, returning its result.
public static ValueTask<T> ExecuteReaderAsync<T>(this SqlCommand command, Func<SqlDataReader, T> transform, CommandBehavior behavior, CancellationToken cancellationToken = default)
Parameters
commandSqlCommandThe command to execute. Its connection is opened if needed and closed again if it was opened here; neither the command nor the connection is disposed.
transformFunc<SqlDataReader, T>The function that reads from the reader and produces the result. Do not let the reader escape it.
behaviorCommandBehaviorThe behavior to use with the data reader. CloseConnection is added when the command opens a closed connection. The default is Default.
cancellationTokenCancellationTokenA token that can cancel opening the connection and executing the command. The default is None.
Returns
- ValueTask<T>
A task that represents the asynchronous operation; its result is the value returned by
transform.
Type Parameters
TThe return type of the transform function.
Remarks
Exceptions from the provider (for example SqlException) propagate unchanged. The reader is disposed, and with it a connection that this method opened, even when the function passed in throws.
Exceptions
- ArgumentNullException
commandortransformis null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled before or while the connection was being opened or the command executed.
ExecuteReaderAsync<T>(SqlCommand, Func<SqlDataReader, ValueTask<T>>, CancellationToken)
Asynchronously executes the command and passes the SqlDataReader to an asynchronous transform function, returning its result.
public static ValueTask<T> ExecuteReaderAsync<T>(this SqlCommand command, Func<SqlDataReader, ValueTask<T>> transform, CancellationToken cancellationToken = default)
Parameters
commandSqlCommandThe command to execute. Its connection is opened if needed and closed again if it was opened here; neither the command nor the connection is disposed.
transformFunc<SqlDataReader, ValueTask<T>>The function that reads from the reader and produces the result. Do not let the reader escape it.
cancellationTokenCancellationTokenA token that can cancel opening the connection and executing the command. The default is None.
Returns
- ValueTask<T>
A task that represents the asynchronous operation; its result is the value produced by
transform.
Type Parameters
TThe return type of the transform function.
Remarks
Exceptions from the provider (for example SqlException) propagate unchanged. The reader is disposed, and with it a connection that this method opened, even when the function passed in throws.
Exceptions
- ArgumentNullException
commandortransformis null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled before or while the connection was being opened or the command executed.
ExecuteReaderAsync<T>(SqlCommand, Func<SqlDataReader, ValueTask<T>>, CommandBehavior, CancellationToken)
Asynchronously executes the command and passes the SqlDataReader to an asynchronous transform function, returning its result.
public static ValueTask<T> ExecuteReaderAsync<T>(this SqlCommand command, Func<SqlDataReader, ValueTask<T>> transform, CommandBehavior behavior, CancellationToken cancellationToken = default)
Parameters
commandSqlCommandThe command to execute. Its connection is opened if needed and closed again if it was opened here; neither the command nor the connection is disposed.
transformFunc<SqlDataReader, ValueTask<T>>The function that reads from the reader and produces the result. Do not let the reader escape it.
behaviorCommandBehaviorThe behavior to use with the data reader. CloseConnection is added when the command opens a closed connection. The default is Default.
cancellationTokenCancellationTokenA token that can cancel opening the connection and executing the command. The default is None.
Returns
- ValueTask<T>
A task that represents the asynchronous operation; its result is the value produced by
transform.
Type Parameters
TThe return type of the transform function.
Remarks
Exceptions from the provider (for example SqlException) propagate unchanged. The reader is disposed, and with it a connection that this method opened, even when the function passed in throws.
Exceptions
- ArgumentNullException
commandortransformis null. The exception is reported through the returned task.- OperationCanceledException
cancellationTokenwas canceled before or while the connection was being opened or the command executed.