Table of Contents

Class SqlStatementObjectExtensions

Namespace
LfrlAnvil.Sql.Statements
Assembly
LfrlAnvil.Sql.Core.dll

Contains various extension methods related to SQL statements.

public static class SqlStatementObjectExtensions
Inheritance
SqlStatementObjectExtensions
Inherited Members

Methods

BeginTransactionAsync(IDbConnection, IsolationLevel, CancellationToken)

Asynchronously creates a new DbTransaction instance from the provided connection.

[Pure]
public static ValueTask<DbTransaction> BeginTransactionAsync(this IDbConnection connection, IsolationLevel isolationLevel, CancellationToken cancellationToken = default)

Parameters

connection IDbConnection

Source connection.

isolationLevel IsolationLevel

Transaction's IsolationLevel.

cancellationToken CancellationToken

Optional CancellationToken.

Returns

ValueTask<DbTransaction>

ValueTask<TResult> that returns a new DbTransaction instance.

Bind(SqlAsyncQueryReader, string)

Binds the provided SqlAsyncQueryReader to the given sql.

[Pure]
public static SqlAsyncQueryReaderExecutor Bind(this SqlAsyncQueryReader reader, string sql)

Parameters

reader SqlAsyncQueryReader

Source query reader.

sql string

SQL to bind with.

Returns

SqlAsyncQueryReaderExecutor

New SqlAsyncQueryReaderExecutor instance.

Bind(SqlAsyncScalarQueryReader, string)

Binds the provided SqlAsyncScalarQueryReader to the given sql.

[Pure]
public static SqlAsyncScalarQueryReaderExecutor Bind(this SqlAsyncScalarQueryReader reader, string sql)

Parameters

reader SqlAsyncScalarQueryReader

Source scalar query reader.

sql string

SQL to bind with.

Returns

SqlAsyncScalarQueryReaderExecutor

New SqlAsyncScalarQueryReaderExecutor instance.

Bind(SqlParameterBinder, IEnumerable<SqlParameter>?)

Binds the provided SqlParameterBinder to the given parameter source.

[Pure]
public static SqlParameterBinderExecutor Bind(this SqlParameterBinder binder, IEnumerable<SqlParameter>? source)

Parameters

binder SqlParameterBinder

Source parameter binder.

source IEnumerable<SqlParameter>

Parameter source to bind with.

Returns

SqlParameterBinderExecutor

New SqlParameterBinderExecutor instance.

Bind(SqlQueryReader, string)

Binds the provided SqlQueryReader to the given sql.

[Pure]
public static SqlQueryReaderExecutor Bind(this SqlQueryReader reader, string sql)

Parameters

reader SqlQueryReader

Source query reader.

sql string

SQL to bind with.

Returns

SqlQueryReaderExecutor

New SqlQueryReaderExecutor instance.

Bind(SqlScalarQueryReader, string)

Binds the provided SqlScalarQueryReader to the given sql.

[Pure]
public static SqlScalarQueryReaderExecutor Bind(this SqlScalarQueryReader reader, string sql)

Parameters

reader SqlScalarQueryReader

Source scalar query reader.

sql string

SQL to bind with.

Returns

SqlScalarQueryReaderExecutor

New SqlScalarQueryReaderExecutor instance.

Bind<TRow>(SqlAsyncQueryReader<TRow>, string)

Binds the provided SqlAsyncQueryReader<TRow> to the given sql.

[Pure]
public static SqlAsyncQueryReaderExecutor<TRow> Bind<TRow>(this SqlAsyncQueryReader<TRow> reader, string sql) where TRow : notnull

Parameters

reader SqlAsyncQueryReader<TRow>

Source query reader.

sql string

SQL to bind with.

Returns

SqlAsyncQueryReaderExecutor<TRow>

New SqlAsyncQueryReaderExecutor<TRow> instance.

Type Parameters

TRow

Row type.

Bind<T>(SqlAsyncScalarQueryReader<T>, string)

Binds the provided SqlAsyncScalarQueryReader<T> to the given sql.

[Pure]
public static SqlAsyncScalarQueryReaderExecutor<T> Bind<T>(this SqlAsyncScalarQueryReader<T> reader, string sql)

Parameters

reader SqlAsyncScalarQueryReader<T>

Source scalar query reader.

sql string

SQL to bind with.

Returns

SqlAsyncScalarQueryReaderExecutor<T>

New SqlAsyncScalarQueryReaderExecutor<T> instance.

Type Parameters

T

Value type.

Bind<TSource>(SqlParameterBinder<TSource>, TSource?)

Binds the provided SqlParameterBinder<TSource> to the given parameter source.

[Pure]
public static SqlParameterBinderExecutor<TSource> Bind<TSource>(this SqlParameterBinder<TSource> binder, TSource? source) where TSource : notnull

Parameters

binder SqlParameterBinder<TSource>

Source parameter binder.

source TSource

Parameter source to bind with.

Returns

SqlParameterBinderExecutor<TSource>

New SqlParameterBinderExecutor<TSource> instance.

Type Parameters

TSource

Parameter source type.

Bind<TRow>(SqlQueryReader<TRow>, string)

Binds the provided SqlQueryReader<TRow> to the given sql.

[Pure]
public static SqlQueryReaderExecutor<TRow> Bind<TRow>(this SqlQueryReader<TRow> reader, string sql) where TRow : notnull

Parameters

reader SqlQueryReader<TRow>

Source query reader.

sql string

SQL to bind with.

Returns

SqlQueryReaderExecutor<TRow>

New SqlQueryReaderExecutor<TRow> instance.

Type Parameters

TRow

Row type.

Bind<T>(SqlScalarQueryReader<T>, string)

Binds the provided SqlScalarQueryReader<T> to the given sql.

[Pure]
public static SqlScalarQueryReaderExecutor<T> Bind<T>(this SqlScalarQueryReader<T> reader, string sql)

Parameters

reader SqlScalarQueryReader<T>

Source scalar query reader.

sql string

SQL to bind with.

Returns

SqlScalarQueryReaderExecutor<T>

New SqlScalarQueryReaderExecutor<T> instance.

Type Parameters

T

Value type.

CreateCommand(DbTransaction)

Creates a new DbCommand instance associated with the provided transaction.

public static DbCommand CreateCommand(this DbTransaction transaction)

Parameters

transaction DbTransaction

Source transaction.

Returns

DbCommand

New DbCommand instance.

CreateCommand(IDbTransaction)

Creates a new IDbCommand instance associated with the provided transaction.

public static IDbCommand CreateCommand(this IDbTransaction transaction)

Parameters

transaction IDbTransaction

Source transaction.

Returns

IDbCommand

New IDbCommand instance.

Execute(IDbCommand)

Executes the provided command.

public static int Execute(this IDbCommand command)

Parameters

command IDbCommand

Source command.

Returns

int

The number of rows affected.

ExecuteAsync(IDbCommand, CancellationToken)

Asynchronously executes the provided command.

public static ValueTask<int> ExecuteAsync(this IDbCommand command, CancellationToken cancellationToken = default)

Parameters

command IDbCommand

Source command.

cancellationToken CancellationToken

Optional CancellationToken.

Returns

ValueTask<int>

ValueTask<TResult> that returns the number of rows affected.

Multi(IDataReader)

Creates a new SqlMultiDataReader instance.

[Pure]
public static SqlMultiDataReader Multi(this IDataReader reader)

Parameters

reader IDataReader

Source data reader.

Returns

SqlMultiDataReader

New SqlMultiDataReader instance.

MultiAsync(IDataReader)

Creates a new SqlAsyncMultiDataReader instance.

[Pure]
public static SqlAsyncMultiDataReader MultiAsync(this IDataReader reader)

Parameters

reader IDataReader

Source data reader.

Returns

SqlAsyncMultiDataReader

New SqlAsyncMultiDataReader instance.

MultiQuery(IDbCommand)

Creates a new SqlMultiDataReader instance.

[Pure]
public static SqlMultiDataReader MultiQuery(this IDbCommand command)

Parameters

command IDbCommand

Source command.

Returns

SqlMultiDataReader

New SqlMultiDataReader instance.

MultiQueryAsync(IDbCommand, CancellationToken)

Creates a new SqlAsyncMultiDataReader instance.

[Pure]
public static ValueTask<SqlAsyncMultiDataReader> MultiQueryAsync(this IDbCommand command, CancellationToken cancellationToken = default)

Parameters

command IDbCommand

Source command.

cancellationToken CancellationToken

Optional CancellationToken.

Returns

ValueTask<SqlAsyncMultiDataReader>

ValueTask<TResult> that returns a new SqlAsyncMultiDataReader instance.

Parameterize<TCommand>(TCommand, SqlParameterBinderExecutor)

Binds parameters to the provided command.

public static TCommand Parameterize<TCommand>(this TCommand command, SqlParameterBinderExecutor executor) where TCommand : IDbCommand

Parameters

command TCommand

Source command.

executor SqlParameterBinderExecutor

SqlParameterBinderExecutor to use for binding.

Returns

TCommand

command.

Type Parameters

TCommand

DB command type.

Parameterize<TCommand, TSource>(TCommand, SqlParameterBinderExecutor<TSource>)

Binds parameters to the provided command.

public static TCommand Parameterize<TCommand, TSource>(this TCommand command, SqlParameterBinderExecutor<TSource> executor) where TCommand : IDbCommand where TSource : notnull

Parameters

command TCommand

Source command.

executor SqlParameterBinderExecutor<TSource>

SqlParameterBinderExecutor<TSource> to use for binding.

Returns

TCommand

command.

Type Parameters

TCommand

DB command type.

TSource

Parameter source type.

Query(IDbCommand, SqlQueryReader, SqlQueryReaderOptions?)

Reads a collection of rows.

[Pure]
public static SqlQueryResult Query(this IDbCommand command, SqlQueryReader reader, SqlQueryReaderOptions? options = null)

Parameters

command IDbCommand

Source command.

reader SqlQueryReader

SqlQueryReader to use for reading.

options SqlQueryReaderOptions?

Query reader options.

Returns

SqlQueryResult

Returns a collection of read rows.

Query(IDbCommand, SqlQueryReaderExecutor, SqlQueryReaderOptions?)

Reads a collection of rows.

[Pure]
public static SqlQueryResult Query(this IDbCommand command, SqlQueryReaderExecutor executor, SqlQueryReaderOptions? options = null)

Parameters

command IDbCommand

Source command.

executor SqlQueryReaderExecutor

SqlQueryReaderExecutor to use for reading.

options SqlQueryReaderOptions?

Query reader options.

Returns

SqlQueryResult

Returns a collection of read rows.

Query(IDbCommand, SqlScalarQueryReader)

Reads a scalar value.

[Pure]
public static SqlScalarQueryResult Query(this IDbCommand command, SqlScalarQueryReader reader)

Parameters

command IDbCommand

Source command.

reader SqlScalarQueryReader

SqlScalarQueryReader to use for reading.

Returns

SqlScalarQueryResult

Returns a read scalar value.

Query(IDbCommand, SqlScalarQueryReaderExecutor)

Reads a scalar value.

[Pure]
public static SqlScalarQueryResult Query(this IDbCommand command, SqlScalarQueryReaderExecutor executor)

Parameters

command IDbCommand

Source command.

executor SqlScalarQueryReaderExecutor

SqlScalarQueryReaderExecutor to use for reading.

Returns

SqlScalarQueryResult

Returns a read scalar value.

QueryAsync(IDbCommand, SqlAsyncQueryReader, SqlQueryReaderOptions?, CancellationToken)

Asynchronously reads a collection of rows.

[Pure]
public static ValueTask<SqlQueryResult> QueryAsync(this IDbCommand command, SqlAsyncQueryReader reader, SqlQueryReaderOptions? options = null, CancellationToken cancellationToken = default)

Parameters

command IDbCommand

Source command.

reader SqlAsyncQueryReader

SqlAsyncQueryReader to use for reading.

options SqlQueryReaderOptions?

Query reader options.

cancellationToken CancellationToken

Optional CancellationToken.

Returns

ValueTask<SqlQueryResult>

ValueTask<TResult> that returns a collection of read rows.

QueryAsync(IDbCommand, SqlAsyncQueryReaderExecutor, SqlQueryReaderOptions?, CancellationToken)

Asynchronously reads a collection of rows.

[Pure]
public static ValueTask<SqlQueryResult> QueryAsync(this IDbCommand command, SqlAsyncQueryReaderExecutor executor, SqlQueryReaderOptions? options = null, CancellationToken cancellationToken = default)

Parameters

command IDbCommand

Source command.

executor SqlAsyncQueryReaderExecutor

SqlAsyncQueryReaderExecutor to use for reading.

options SqlQueryReaderOptions?

Query reader options.

cancellationToken CancellationToken

Optional CancellationToken.

Returns

ValueTask<SqlQueryResult>

ValueTask<TResult> that returns a collection of read rows.

QueryAsync(IDbCommand, SqlAsyncScalarQueryReader, CancellationToken)

Asynchronously reads a scalar value.

[Pure]
public static ValueTask<SqlScalarQueryResult> QueryAsync(this IDbCommand command, SqlAsyncScalarQueryReader reader, CancellationToken cancellationToken = default)

Parameters

command IDbCommand

Source command.

reader SqlAsyncScalarQueryReader

SqlAsyncScalarQueryReader to use for reading.

cancellationToken CancellationToken

Optional CancellationToken.

Returns

ValueTask<SqlScalarQueryResult>

ValueTask<TResult> that returns a read scalar value.

QueryAsync(IDbCommand, SqlAsyncScalarQueryReaderExecutor, CancellationToken)

Asynchronously reads a scalar value.

[Pure]
public static ValueTask<SqlScalarQueryResult> QueryAsync(this IDbCommand command, SqlAsyncScalarQueryReaderExecutor executor, CancellationToken cancellationToken = default)

Parameters

command IDbCommand

Source command.

executor SqlAsyncScalarQueryReaderExecutor

SqlAsyncScalarQueryReaderExecutor to use for reading.

cancellationToken CancellationToken

Optional CancellationToken.

Returns

ValueTask<SqlScalarQueryResult>

ValueTask<TResult> that returns a read scalar value.

QueryAsync<TRow>(IDbCommand, SqlAsyncQueryReaderExecutor<TRow>, SqlQueryReaderOptions?, CancellationToken)

Asynchronously reads a collection of rows.

[Pure]
public static ValueTask<SqlQueryResult<TRow>> QueryAsync<TRow>(this IDbCommand command, SqlAsyncQueryReaderExecutor<TRow> executor, SqlQueryReaderOptions? options = null, CancellationToken cancellationToken = default) where TRow : notnull

Parameters

command IDbCommand

Source command.

executor SqlAsyncQueryReaderExecutor<TRow>

SqlAsyncQueryReaderExecutor<TRow> to use for reading.

options SqlQueryReaderOptions?

Query reader options.

cancellationToken CancellationToken

Optional CancellationToken.

Returns

ValueTask<SqlQueryResult<TRow>>

ValueTask<TResult> that returns a collection of read rows.

Type Parameters

TRow

Row type.

QueryAsync<TRow>(IDbCommand, SqlAsyncQueryReader<TRow>, SqlQueryReaderOptions?, CancellationToken)

Asynchronously reads a collection of rows.

[Pure]
public static ValueTask<SqlQueryResult<TRow>> QueryAsync<TRow>(this IDbCommand command, SqlAsyncQueryReader<TRow> reader, SqlQueryReaderOptions? options = null, CancellationToken cancellationToken = default) where TRow : notnull

Parameters

command IDbCommand

Source command.

reader SqlAsyncQueryReader<TRow>

SqlAsyncQueryReader<TRow> to use for reading.

options SqlQueryReaderOptions?

Query reader options.

cancellationToken CancellationToken

Optional CancellationToken.

Returns

ValueTask<SqlQueryResult<TRow>>

ValueTask<TResult> that returns a collection of read rows.

Type Parameters

TRow

Row type.

QueryAsync<T>(IDbCommand, SqlAsyncScalarQueryReaderExecutor<T>, CancellationToken)

Asynchronously reads a scalar value.

[Pure]
public static ValueTask<SqlScalarQueryResult<T>> QueryAsync<T>(this IDbCommand command, SqlAsyncScalarQueryReaderExecutor<T> executor, CancellationToken cancellationToken = default)

Parameters

command IDbCommand

Source command.

executor SqlAsyncScalarQueryReaderExecutor<T>

SqlAsyncScalarQueryReaderExecutor<T> to use for reading.

cancellationToken CancellationToken

Optional CancellationToken.

Returns

ValueTask<SqlScalarQueryResult<T>>

ValueTask<TResult> that returns a read scalar value.

Type Parameters

T

Value type.

QueryAsync<T>(IDbCommand, SqlAsyncScalarQueryReader<T>, CancellationToken)

Asynchronously reads a scalar value.

[Pure]
public static ValueTask<SqlScalarQueryResult<T>> QueryAsync<T>(this IDbCommand command, SqlAsyncScalarQueryReader<T> reader, CancellationToken cancellationToken = default)

Parameters

command IDbCommand

Source command.

reader SqlAsyncScalarQueryReader<T>

SqlAsyncScalarQueryReader<T> to use for reading.

cancellationToken CancellationToken

Optional CancellationToken.

Returns

ValueTask<SqlScalarQueryResult<T>>

ValueTask<TResult> that returns a read scalar value.

Type Parameters

T

Value type.

Query<TRow>(IDbCommand, SqlQueryReaderExecutor<TRow>, SqlQueryReaderOptions?)

Reads a collection of rows.

[Pure]
public static SqlQueryResult<TRow> Query<TRow>(this IDbCommand command, SqlQueryReaderExecutor<TRow> executor, SqlQueryReaderOptions? options = null) where TRow : notnull

Parameters

command IDbCommand

Source command.

executor SqlQueryReaderExecutor<TRow>

SqlQueryReaderExecutor<TRow> to use for reading.

options SqlQueryReaderOptions?

Query reader options.

Returns

SqlQueryResult<TRow>

Returns a collection of read rows.

Type Parameters

TRow

Row type.

Query<TRow>(IDbCommand, SqlQueryReader<TRow>, SqlQueryReaderOptions?)

Reads a collection of rows.

[Pure]
public static SqlQueryResult<TRow> Query<TRow>(this IDbCommand command, SqlQueryReader<TRow> reader, SqlQueryReaderOptions? options = null) where TRow : notnull

Parameters

command IDbCommand

Source command.

reader SqlQueryReader<TRow>

SqlQueryReader<TRow> to use for reading.

options SqlQueryReaderOptions?

Query reader options.

Returns

SqlQueryResult<TRow>

Returns a collection of read rows.

Type Parameters

TRow

Row type.

Query<T>(IDbCommand, SqlScalarQueryReaderExecutor<T>)

Reads a scalar value.

[Pure]
public static SqlScalarQueryResult<T> Query<T>(this IDbCommand command, SqlScalarQueryReaderExecutor<T> executor)

Parameters

command IDbCommand

Source command.

executor SqlScalarQueryReaderExecutor<T>

SqlScalarQueryReaderExecutor<T> to use for reading.

Returns

SqlScalarQueryResult<T>

Returns a read scalar value.

Type Parameters

T

Value type.

Query<T>(IDbCommand, SqlScalarQueryReader<T>)

Reads a scalar value.

[Pure]
public static SqlScalarQueryResult<T> Query<T>(this IDbCommand command, SqlScalarQueryReader<T> reader)

Parameters

command IDbCommand

Source command.

reader SqlScalarQueryReader<T>

SqlScalarQueryReader<T> to use for reading.

Returns

SqlScalarQueryResult<T>

Returns a read scalar value.

Type Parameters

T

Value type.

SetText<TCommand>(TCommand, string)

Updates the CommandText of the provided command.

public static TCommand SetText<TCommand>(this TCommand command, string sql) where TCommand : IDbCommand

Parameters

command TCommand

Source command.

sql string

Value to set.

Returns

TCommand

command.

Type Parameters

TCommand

DB command type.

SetTimeout<TCommand>(TCommand, TimeSpan)

Updates the CommandTimeout of the provided command.

public static TCommand SetTimeout<TCommand>(this TCommand command, TimeSpan timeout) where TCommand : IDbCommand

Parameters

command TCommand

Source command.

timeout TimeSpan

Value to set.

Returns

TCommand

command.

Type Parameters

TCommand

DB command type.

Exceptions

ArgumentException

When timeout is less 0.