Table of Contents

Class SqlBuilderExtension

Namespace
IceCoffee.Db4Net.Extensions
Assembly
IceCoffee.Db4Net.dll

Provides extension methods for SQL builders.

public static class SqlBuilderExtension
Inheritance
SqlBuilderExtension
Inherited Members

Methods

ExecuteAsync<TId>(ISqlInsertAndGetIdBuilder, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the INSERT command and returns the newly inserted identity value of type TId.

public static Task<TId?> ExecuteAsync<TId>(this ISqlInsertAndGetIdBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder ISqlInsertAndGetIdBuilder

An instance of IceCoffee.Db4Net.Core.SqlBuilders.ISqlInsertAndGetIdBuilder.

transaction IDbTransaction

An optional database transaction.

buffered bool

Specifies whether results are buffered.

commandTimeout int?

The command timeout in seconds.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<TId>

A task representing the asynchronous operation, with the new identity value.

Type Parameters

TId

The type of the identity value to return.

ExecuteAsync<TEntity>(SqlDeleteBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes a DELETE statement based on the specified IceCoffee.Db4Net.Core.SqlBuilders.SqlDeleteBuilder<TEntity> and returns the number of affected rows.

public static Task<int> ExecuteAsync<TEntity>(this SqlDeleteBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlDeleteBuilder<TEntity>

An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlDeleteBuilder<TEntity> containing the delete command.

transaction IDbTransaction

The optional database transaction to enlist in.

buffered bool

Indicates whether the query results should be buffered.

commandTimeout int?

An optional timeout in seconds for the command.

cancellationToken CancellationToken

A token that may be used to cancel the operation.

Returns

Task<int>

A task that represents the asynchronous operation and returns the number of rows affected by the DELETE operation.

Type Parameters

TEntity

The entity type for the DELETE operation.

ExecuteAsync<TEntity>(SqlDeleteEntityBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes a DELETE statement using the specified IceCoffee.Db4Net.Core.SqlBuilders.SqlDeleteEntityBuilder<TEntity> and returns the number of affected rows.

public static Task<int> ExecuteAsync<TEntity>(this SqlDeleteEntityBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlDeleteEntityBuilder<TEntity>

An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlDeleteEntityBuilder<TEntity> containing the delete command.

transaction IDbTransaction

The optional database transaction to enlist in.

buffered bool

Indicates whether the query results should be buffered.

commandTimeout int?

An optional timeout in seconds for the command.

cancellationToken CancellationToken

A token that may be used to cancel the operation.

Returns

Task<int>

A task that represents the asynchronous operation and returns the number of rows affected by the DELETE operation.

Type Parameters

TEntity

The entity type for the DELETE operation.

ExecuteAsync<TEntity>(SqlInsertBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the INSERT command built by the specified IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertBuilder<TEntity>.

public static Task<int> ExecuteAsync<TEntity>(this SqlInsertBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlInsertBuilder<TEntity>

An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertBuilder<TEntity>.

transaction IDbTransaction

An optional database transaction.

buffered bool

Specifies whether results are buffered.

commandTimeout int?

The command timeout in seconds.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<int>

A task representing the asynchronous operation, with the number of rows affected.

Type Parameters

TEntity

The entity type for the insert operation.

ExecuteAsync<TEntity>(SqlInsertEntityBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the INSERT command built by the specified IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertEntityBuilder<TEntity>, typically using entity objects.

public static Task<int> ExecuteAsync<TEntity>(this SqlInsertEntityBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlInsertEntityBuilder<TEntity>

An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertEntityBuilder<TEntity>.

transaction IDbTransaction

An optional database transaction.

buffered bool

Specifies whether results are buffered.

commandTimeout int?

The command timeout in seconds.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<int>

A task representing the asynchronous operation, with the number of rows affected.

Type Parameters

TEntity

The entity type for the insert operation.

ExecuteAsync<TEntity>(SqlInsertOrIgnoreBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the INSERT OR IGNORE command built by the specified IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertOrIgnoreBuilder<TEntity>.

public static Task<int> ExecuteAsync<TEntity>(this SqlInsertOrIgnoreBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlInsertOrIgnoreBuilder<TEntity>

An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertOrIgnoreBuilder<TEntity>.

transaction IDbTransaction

An optional database transaction.

buffered bool

Specifies whether results are buffered.

commandTimeout int?

The command timeout in seconds.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<int>

A task representing the asynchronous operation, with the number of rows affected.

Type Parameters

TEntity

The entity type for the insert operation.

ExecuteAsync<TEntity>(SqlInsertOrReplaceBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the INSERT OR REPLACE command built by the specified IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertOrReplaceBuilder<TEntity>.

public static Task<int> ExecuteAsync<TEntity>(this SqlInsertOrReplaceBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlInsertOrReplaceBuilder<TEntity>

An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertOrReplaceBuilder<TEntity>.

transaction IDbTransaction

An optional database transaction.

buffered bool

Specifies whether results are buffered.

commandTimeout int?

The command timeout in seconds.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<int>

A task representing the asynchronous operation, with the number of rows affected.

Type Parameters

TEntity

The entity type for the insert operation.

ExecuteAsync<TEntity>(SqlUpdateBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes an update command based on the provided IceCoffee.Db4Net.Core.SqlBuilders.SqlUpdateBuilder<TEntity> and returns the number of affected rows.

public static Task<int> ExecuteAsync<TEntity>(this SqlUpdateBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlUpdateBuilder<TEntity>

The IceCoffee.Db4Net.Core.SqlBuilders.SqlUpdateBuilder<TEntity> instance that defines the update operation.

transaction IDbTransaction

The database transaction to use for this command. (Optional)

buffered bool

A value indicating whether the command should be buffered. (Optional, defaults to true)

commandTimeout int?

The time in seconds to wait for the command to execute. (Optional)

cancellationToken CancellationToken

A cancellation token that can be used to cancel the operation. (Optional)

Returns

Task<int>

A Task<TResult> that represents the asynchronous operation. The task result contains the number of rows affected.

Type Parameters

TEntity

The type of the entity to be updated.

ExecuteAsync<TEntity>(SqlUpdateEntityBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes an update command based on the provided IceCoffee.Db4Net.Core.SqlBuilders.SqlUpdateEntityBuilder<TEntity> and returns the number of affected rows.

public static Task<int> ExecuteAsync<TEntity>(this SqlUpdateEntityBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlUpdateEntityBuilder<TEntity>

The IceCoffee.Db4Net.Core.SqlBuilders.SqlUpdateEntityBuilder<TEntity> instance that defines the update operation.

transaction IDbTransaction

The database transaction to use for this command. (Optional)

buffered bool

A value indicating whether the command should be buffered. (Optional, defaults to true)

commandTimeout int?

The time in seconds to wait for the command to execute. (Optional)

cancellationToken CancellationToken

A cancellation token that can be used to cancel the operation. (Optional)

Returns

Task<int>

A Task<TResult> that represents the asynchronous operation. The task result contains the number of rows affected.

Type Parameters

TEntity

The type of the entity to be updated.

Execute<TId>(ISqlInsertAndGetIdBuilder, IDbTransaction?, bool, int?, CancellationToken)

Executes the INSERT command and returns the newly inserted identity value of type TId.

public static TId? Execute<TId>(this ISqlInsertAndGetIdBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder ISqlInsertAndGetIdBuilder

An instance of IceCoffee.Db4Net.Core.SqlBuilders.ISqlInsertAndGetIdBuilder.

transaction IDbTransaction

An optional database transaction.

buffered bool

Specifies whether results are buffered.

commandTimeout int?

The command timeout in seconds.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

TId

The identity value of the inserted record.

Type Parameters

TId

The type of the identity value to return.

Execute<TEntity>(SqlDeleteBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes a DELETE statement based on the specified IceCoffee.Db4Net.Core.SqlBuilders.SqlDeleteBuilder<TEntity> and returns the number of affected rows.

public static int Execute<TEntity>(this SqlDeleteBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlDeleteBuilder<TEntity>

An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlDeleteBuilder<TEntity> containing the delete command.

transaction IDbTransaction

The optional database transaction to enlist in.

buffered bool

Indicates whether the query results should be buffered.

commandTimeout int?

An optional timeout in seconds for the command.

cancellationToken CancellationToken

A token that may be used to cancel the operation.

Returns

int

The number of rows affected by the DELETE operation.

Type Parameters

TEntity

The entity type for the DELETE operation.

Execute<TEntity>(SqlDeleteEntityBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes a DELETE statement using the specified IceCoffee.Db4Net.Core.SqlBuilders.SqlDeleteEntityBuilder<TEntity> and returns the number of affected rows.

public static int Execute<TEntity>(this SqlDeleteEntityBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlDeleteEntityBuilder<TEntity>

An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlDeleteEntityBuilder<TEntity> containing the delete command.

transaction IDbTransaction

The optional database transaction to enlist in.

buffered bool

Indicates whether the query results should be buffered.

commandTimeout int?

An optional timeout in seconds for the command.

cancellationToken CancellationToken

A token that may be used to cancel the operation.

Returns

int

The number of rows affected by the DELETE operation.

Type Parameters

TEntity

The entity type for the DELETE operation.

Execute<TEntity>(SqlInsertBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes the INSERT command built by the specified IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertBuilder<TEntity>.

public static int Execute<TEntity>(this SqlInsertBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlInsertBuilder<TEntity>

An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertBuilder<TEntity>.

transaction IDbTransaction

An optional database transaction.

buffered bool

Specifies whether results are buffered.

commandTimeout int?

The command timeout in seconds.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

int

The number of rows affected.

Type Parameters

TEntity

The entity type for the insert operation.

Execute<TEntity>(SqlInsertEntityBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes the INSERT command built by the specified IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertEntityBuilder<TEntity>, typically using entity objects.

public static int Execute<TEntity>(this SqlInsertEntityBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlInsertEntityBuilder<TEntity>

An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertEntityBuilder<TEntity>.

transaction IDbTransaction

An optional database transaction.

buffered bool

Specifies whether results are buffered.

commandTimeout int?

The command timeout in seconds.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

int

The number of rows affected.

Type Parameters

TEntity

The entity type for the insert operation.

Execute<TEntity>(SqlInsertOrIgnoreBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes the INSERT OR IGNORE command built by the specified IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertOrIgnoreBuilder<TEntity>.

public static int Execute<TEntity>(this SqlInsertOrIgnoreBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlInsertOrIgnoreBuilder<TEntity>

An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertOrIgnoreBuilder<TEntity>.

transaction IDbTransaction

An optional database transaction.

buffered bool

Specifies whether results are buffered.

commandTimeout int?

The command timeout in seconds.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

int

The number of rows affected.

Type Parameters

TEntity

The entity type for the insert operation.

Execute<TEntity>(SqlInsertOrReplaceBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes the INSERT OR REPLACE command built by the specified IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertOrReplaceBuilder<TEntity>.

public static int Execute<TEntity>(this SqlInsertOrReplaceBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlInsertOrReplaceBuilder<TEntity>

An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertOrReplaceBuilder<TEntity>.

transaction IDbTransaction

An optional database transaction.

buffered bool

Specifies whether results are buffered.

commandTimeout int?

The command timeout in seconds.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

int

The number of rows affected.

Type Parameters

TEntity

The entity type for the insert operation.

Execute<TEntity>(SqlUpdateBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes an update command based on the provided IceCoffee.Db4Net.Core.SqlBuilders.SqlUpdateBuilder<TEntity> and returns the number of affected rows.

public static int Execute<TEntity>(this SqlUpdateBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlUpdateBuilder<TEntity>

The IceCoffee.Db4Net.Core.SqlBuilders.SqlUpdateBuilder<TEntity> instance that defines the update operation.

transaction IDbTransaction

The database transaction to use for this command. (Optional)

buffered bool

A value indicating whether the command should be buffered. (Optional, defaults to true)

commandTimeout int?

The time in seconds to wait for the command to execute. (Optional)

cancellationToken CancellationToken

A cancellation token that can be used to cancel the operation. (Optional)

Returns

int

The number of rows affected.

Type Parameters

TEntity

The type of the entity to be updated.

Execute<TEntity>(SqlUpdateEntityBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes an update command based on the provided IceCoffee.Db4Net.Core.SqlBuilders.SqlUpdateEntityBuilder<TEntity> and returns the number of affected rows.

public static int Execute<TEntity>(this SqlUpdateEntityBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlUpdateEntityBuilder<TEntity>

The IceCoffee.Db4Net.Core.SqlBuilders.SqlUpdateEntityBuilder<TEntity> instance that defines the update operation.

transaction IDbTransaction

The database transaction to use for this command. (Optional)

buffered bool

A value indicating whether the command should be buffered. (Optional, defaults to true)

commandTimeout int?

The time in seconds to wait for the command to execute. (Optional)

cancellationToken CancellationToken

A cancellation token that can be used to cancel the operation. (Optional)

Returns

int

The number of rows affected.

Type Parameters

TEntity

The type of the entity to be updated.

Get(SqlQueryExistsBuilder, IDbTransaction?, bool, int?, CancellationToken)

Executes the exists SQL query and returns a boolean indicating if any record exists.

public static bool Get(this SqlQueryExistsBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryExistsBuilder

The exists SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query result is buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

bool

True if a record exists; otherwise, false.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetAsync(SqlQueryExistsBuilder, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the exists SQL query and returns a boolean indicating if any record exists.

public static Task<bool> GetAsync(this SqlQueryExistsBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryExistsBuilder

The exists SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query result is buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<bool>

A task that represents the asynchronous operation. The task result is true if a record exists; otherwise, false.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetAsync<T>(ISqlQueryCountBuilder, IDbTransaction?, int?, CancellationToken)

Executes the SQL query defined by the sqlBuilder and retrieves a single value of type T.

public static Task<T?> GetAsync<T>(this ISqlQueryCountBuilder sqlBuilder, IDbTransaction? transaction = null, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder ISqlQueryCountBuilder

The SQL query builder that defines the query to execute.

transaction IDbTransaction

An optional database transaction to associate with the query execution. If null, a new connection is created.

commandTimeout int?

An optional timeout value, in seconds, for the query execution. If null, the default timeout is used.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<T>

A task representing the asynchronous operation. The task result contains the value of type T retrieved from the query. If no value is found, the result is null.

Type Parameters

T

The type of the value to retrieve from the query result.

Remarks

This method uses the SQL query defined by the sqlBuilder to execute a scalar query. If transaction is provided, the query is executed within the scope of the transaction. Otherwise, a new database connection is created for the query execution.

GetAsync<TEntity>(SqlQueryCountBuilder<TEntity>, IDbTransaction?, int?, CancellationToken)

Executes the SQL query represented by the IceCoffee.Db4Net.Core.SqlBuilders.SqlQueryCountBuilder<TEntity> instance and retrieves the resulting count as a long value.

public static Task<long> GetAsync<TEntity>(this SqlQueryCountBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryCountBuilder<TEntity>

The IceCoffee.Db4Net.Core.SqlBuilders.SqlQueryCountBuilder<TEntity> instance containing the SQL query and its parameters.

transaction IDbTransaction

An optional IDbTransaction to associate with the query execution. If null, a new database connection is created.

commandTimeout int?

An optional timeout value, in seconds, for the command execution. If null, the default timeout is used.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task<long>

The count resulting from the execution of the SQL query as a long value.

Type Parameters

TEntity

The type of the entity associated with the SQL query.

Remarks

This method uses the SQL query and parameters defined in the sqlBuilder to execute a scalar query that returns a count. If a transaction is provided, the query is executed within the context of that transaction; otherwise, a new database connection is created.

GetAsync<TEntity>(SqlQueryExistsBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes the SQL query built by the IceCoffee.Db4Net.Core.SqlBuilders.SqlQueryExistsBuilder<TEntity> and determines whether the query returns a result.

public static Task<bool> GetAsync<TEntity>(this SqlQueryExistsBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryExistsBuilder<TEntity>

The IceCoffee.Db4Net.Core.SqlBuilders.SqlQueryExistsBuilder<TEntity> instance used to construct the SQL query.

transaction IDbTransaction

An optional IDbTransaction to associate with the query execution. If null, the query will execute without a transaction.

buffered bool

Indicates whether the query results should be buffered. Set to true to enable buffering; otherwise, false.

commandTimeout int?

An optional timeout value, in seconds, for the command execution. If null, the default timeout is used.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task<bool>

true if the query returns a result; otherwise, false.

Type Parameters

TEntity

The type of the entity associated with the SQL query.

Remarks

This method uses the SQL query defined by the sqlBuilder to check for the existence of a result. If a transaction is provided, the query will execute within the context of that transaction.

GetFirstAsync<T>(SqlQueryBuilder, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the SQL query and returns the first record of type T.

public static Task<T> GetFirstAsync<T>(this SqlQueryBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<T>

A task that represents the asynchronous operation. The task result contains the first record of type T.

Type Parameters

T

The type of the returned record.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetFirstAsync<TEntity>(SqlQueryBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the SQL query and returns the first record of type TEntity.

public static Task<TEntity> GetFirstAsync<TEntity>(this SqlQueryBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder<TEntity>

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TEntity>

A task that represents the asynchronous operation. The task result contains the first record of type TEntity.

Type Parameters

TEntity

The entity type of the returned record.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetFirstOrDefaultAsync<T>(SqlQueryBuilder, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the SQL query and returns the first record of type T or default if not found.

public static Task<T?> GetFirstOrDefaultAsync<T>(this SqlQueryBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<T>

A task that represents the asynchronous operation. The task result contains the first record of type T or default if not found.

Type Parameters

T

The type of the returned record.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetFirstOrDefaultAsync<TEntity>(SqlQueryBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the SQL query and returns the first record of type TEntity or default if not found.

public static Task<TEntity?> GetFirstOrDefaultAsync<TEntity>(this SqlQueryBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder<TEntity>

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TEntity>

A task that represents the asynchronous operation. The task result contains the first record of type TEntity or default if not found.

Type Parameters

TEntity

The entity type of the returned record.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetFirstOrDefault<T>(SqlQueryBuilder, IDbTransaction?, bool, int?, CancellationToken)

Executes the SQL query and returns the first record of type T or default if not found.

public static T? GetFirstOrDefault<T>(this SqlQueryBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

T

The first record of type T or default if not found.

Type Parameters

T

The type of the returned record.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetFirstOrDefault<TEntity>(SqlQueryBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes the SQL query and returns the first record of type TEntity or default if not found.

public static TEntity? GetFirstOrDefault<TEntity>(this SqlQueryBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder<TEntity>

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

TEntity

The first record of type TEntity or default if not found.

Type Parameters

TEntity

The entity type of the returned record.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetFirst<T>(SqlQueryBuilder, IDbTransaction?, bool, int?, CancellationToken)

Executes the SQL query and returns the first record of type T.

public static T GetFirst<T>(this SqlQueryBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

T

The first record of type T.

Type Parameters

T

The type of the returned record.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetFirst<TEntity>(SqlQueryBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes the SQL query and returns the first record of type TEntity.

public static TEntity GetFirst<TEntity>(this SqlQueryBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder<TEntity>

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

TEntity

The first record of type TEntity.

Type Parameters

TEntity

The entity type of the returned record.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetListAsync<T>(SqlQueryBuilder, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the SQL query and returns a list of records of type T.

public static Task<IEnumerable<T>> GetListAsync<T>(this SqlQueryBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IEnumerable<T>>

A task that represents the asynchronous operation. The task result contains an enumerable collection of records of type T.

Type Parameters

T

The type of the returned records.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetListAsync<TEntity>(SqlQueryBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the SQL query and returns a list of records of type TEntity.

public static Task<IEnumerable<TEntity>> GetListAsync<TEntity>(this SqlQueryBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder<TEntity>

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IEnumerable<TEntity>>

A task that represents the asynchronous operation. The task result contains an enumerable collection of records of type TEntity.

Type Parameters

TEntity

The entity type of the returned records.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetListAsync<T>(SqlQueryPagedBuilder, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the paged SQL query and returns a list of records of type T.

public static Task<IEnumerable<T>> GetListAsync<T>(this SqlQueryPagedBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryPagedBuilder

The paged SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IEnumerable<T>>

A task that represents the asynchronous operation. The task result contains an enumerable collection of records of type T.

Type Parameters

T

The type of the returned records.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetListAsync<TEntity>(SqlQueryPagedBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the paged SQL query and returns a list of records of type TEntity.

public static Task<IEnumerable<TEntity>> GetListAsync<TEntity>(this SqlQueryPagedBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryPagedBuilder<TEntity>

The paged SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IEnumerable<TEntity>>

A task that represents the asynchronous operation. The task result contains an enumerable collection of records of type TEntity.

Type Parameters

TEntity

The entity type of the returned records.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetListAsync<T>(SqlQueryStoredProcedureBuilder, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the stored procedure query and returns a list of records of type T.

public static Task<IEnumerable<T>> GetListAsync<T>(this SqlQueryStoredProcedureBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryStoredProcedureBuilder

The stored procedure query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IEnumerable<T>>

A task that represents the asynchronous operation. The task result contains an enumerable collection of records of type T.

Type Parameters

T

The type of the returned records.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetListAsync<TEntity>(SqlQueryStoredProcedureBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the stored procedure query and returns a list of records of type TEntity.

public static Task<IEnumerable<TEntity>> GetListAsync<TEntity>(this SqlQueryStoredProcedureBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryStoredProcedureBuilder<TEntity>

The stored procedure query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IEnumerable<TEntity>>

A task that represents the asynchronous operation. The task result contains an enumerable collection of records of type TEntity.

Type Parameters

TEntity

The entity type of the returned records.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetList<T>(SqlQueryBuilder, IDbTransaction?, bool, int?, CancellationToken)

Executes the SQL query and returns a list of records of type T.

public static IEnumerable<T> GetList<T>(this SqlQueryBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

IEnumerable<T>

An enumerable collection of records of type T.

Type Parameters

T

The type of the returned records.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetList<TEntity>(SqlQueryBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes the SQL query and returns a list of records of type TEntity.

public static IEnumerable<TEntity> GetList<TEntity>(this SqlQueryBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder<TEntity>

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

IEnumerable<TEntity>

An enumerable collection of records of type TEntity.

Type Parameters

TEntity

The entity type of the returned records.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetList<T>(SqlQueryPagedBuilder, IDbTransaction?, bool, int?, CancellationToken)

Executes the paged SQL query and returns a list of records of type T.

public static IEnumerable<T> GetList<T>(this SqlQueryPagedBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryPagedBuilder

The paged SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

IEnumerable<T>

An enumerable collection of records of type T.

Type Parameters

T

The type of the returned records.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetList<TEntity>(SqlQueryPagedBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes the paged SQL query and returns a list of records of type TEntity.

public static IEnumerable<TEntity> GetList<TEntity>(this SqlQueryPagedBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryPagedBuilder<TEntity>

The paged SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

IEnumerable<TEntity>

An enumerable collection of records of type TEntity.

Type Parameters

TEntity

The entity type of the returned records.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetList<T>(SqlQueryStoredProcedureBuilder, IDbTransaction?, bool, int?, CancellationToken)

Executes the stored procedure query and returns a list of records of type T.

public static IEnumerable<T> GetList<T>(this SqlQueryStoredProcedureBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryStoredProcedureBuilder

The stored procedure query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

IEnumerable<T>

An enumerable collection of records of type T.

Type Parameters

T

The type of the returned records.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetList<TEntity>(SqlQueryStoredProcedureBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes the stored procedure query and returns a list of records of type TEntity.

public static IEnumerable<TEntity> GetList<TEntity>(this SqlQueryStoredProcedureBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryStoredProcedureBuilder<TEntity>

The stored procedure query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

IEnumerable<TEntity>

An enumerable collection of records of type TEntity.

Type Parameters

TEntity

The entity type of the returned records.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetPagedResultAsync<T>(SqlQueryPagedBuilder, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the paged SQL query and returns the paged result including records and total count.

public static Task<PagedResult<T>> GetPagedResultAsync<T>(this SqlQueryPagedBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryPagedBuilder

The paged SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<PagedResult<T>>

A task that represents the asynchronous operation. The task result contains a paged result with total count and a collection of records of type T.

Type Parameters

T

The type of the returned records.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetPagedResultAsync<TEntity>(SqlQueryPagedBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the paged SQL query and returns the paged result including records and total count.

public static Task<PagedResult<TEntity>> GetPagedResultAsync<TEntity>(this SqlQueryPagedBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryPagedBuilder<TEntity>

The paged SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<PagedResult<TEntity>>

A task that represents the asynchronous operation. The task result contains a paged result with total count and a collection of records of type TEntity.

Type Parameters

TEntity

The entity type of the returned records.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetPagedResult<T>(SqlQueryPagedBuilder, IDbTransaction?, bool, int?, CancellationToken)

Executes the paged SQL query and returns the paged result including records and total count.

public static PagedResult<T> GetPagedResult<T>(this SqlQueryPagedBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryPagedBuilder

The paged SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

PagedResult<T>

A paged result containing the total count and a collection of records of type T.

Type Parameters

T

The type of the returned records.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetPagedResult<TEntity>(SqlQueryPagedBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes the paged SQL query and returns the paged result including records and total count.

public static PagedResult<TEntity> GetPagedResult<TEntity>(this SqlQueryPagedBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryPagedBuilder<TEntity>

The paged SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

PagedResult<TEntity>

A paged result containing the total count and a collection of records of type TEntity.

Type Parameters

TEntity

The entity type of the returned records.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetSingleAsync<T>(SqlQueryBuilder, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the SQL query and returns a single record of type T.

public static Task<T> GetSingleAsync<T>(this SqlQueryBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<T>

A task that represents the asynchronous operation. The task result contains a single record of type T.

Type Parameters

T

The type of the returned record.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetSingleAsync<TEntity>(SqlQueryBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the SQL query and returns a single record of type TEntity.

public static Task<TEntity> GetSingleAsync<TEntity>(this SqlQueryBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder<TEntity>

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TEntity>

A task that represents the asynchronous operation. The task result contains a single record of type TEntity.

Type Parameters

TEntity

The entity type of the returned record.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetSingleOrDefaultAsync<T>(SqlQueryBuilder, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the SQL query and returns a single record of type T or default if not found.

public static Task<T?> GetSingleOrDefaultAsync<T>(this SqlQueryBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<T>

A task that represents the asynchronous operation. The task result contains a single record of type T or default if not found.

Type Parameters

T

The type of the returned record.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetSingleOrDefaultAsync<TEntity>(SqlQueryBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Asynchronously executes the SQL query and returns a single record of type TEntity or default if not found.

public static Task<TEntity?> GetSingleOrDefaultAsync<TEntity>(this SqlQueryBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder<TEntity>

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TEntity>

A task that represents the asynchronous operation. The task result contains a single record of type TEntity or default if not found.

Type Parameters

TEntity

The entity type of the returned record.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetSingleOrDefault<T>(SqlQueryBuilder, IDbTransaction?, bool, int?, CancellationToken)

Executes the SQL query and returns a single record of type T or default if not found.

public static T? GetSingleOrDefault<T>(this SqlQueryBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

T

A single record of type T or default if not found.

Type Parameters

T

The type of the returned record.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetSingleOrDefault<TEntity>(SqlQueryBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes the SQL query and returns a single record of type TEntity or default if not found.

public static TEntity? GetSingleOrDefault<TEntity>(this SqlQueryBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder<TEntity>

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

TEntity

A single record of type TEntity or default if not found.

Type Parameters

TEntity

The entity type of the returned record.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetSingle<T>(SqlQueryBuilder, IDbTransaction?, bool, int?, CancellationToken)

Executes the SQL query and returns a single record of type T.

public static T GetSingle<T>(this SqlQueryBuilder sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

T

A single record of type T.

Type Parameters

T

The type of the returned record.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

GetSingle<TEntity>(SqlQueryBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes the SQL query and returns a single record of type TEntity.

public static TEntity GetSingle<TEntity>(this SqlQueryBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryBuilder<TEntity>

The SQL query builder.

transaction IDbTransaction

The optional database transaction.

buffered bool

Determines whether the query results are buffered.

commandTimeout int?

The optional command timeout.

cancellationToken CancellationToken

The cancellation token.

Returns

TEntity

A single record of type TEntity.

Type Parameters

TEntity

The entity type of the returned record.

Exceptions

SqlExecuteException

Thrown when SQL execution fails.

Get<T>(ISqlQueryCountBuilder, IDbTransaction?, int?, CancellationToken)

Executes the SQL query defined by the sqlBuilder and retrieves a single scalar value of type T.

public static T? Get<T>(this ISqlQueryCountBuilder sqlBuilder, IDbTransaction? transaction = null, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder ISqlQueryCountBuilder

The SQL query builder that defines the query to execute.

transaction IDbTransaction

An optional database transaction to associate with the query execution. If null, the query will execute without a transaction.

commandTimeout int?

An optional timeout value, in seconds, for the command execution. If null, the default timeout is used.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

T

The scalar value of type T retrieved from the query execution, or null if the query result is empty.

Type Parameters

T

The type of the scalar value to retrieve.

Remarks

This method uses the SQL query defined by the sqlBuilder to execute a scalar query. If a transaction is provided, the query will execute within the scope of that transaction. Otherwise, a new database connection is created based on the sqlBuilder configuration.

Get<TEntity>(SqlQueryCountBuilder<TEntity>, IDbTransaction?, int?, CancellationToken)

Executes the SQL query represented by the IceCoffee.Db4Net.Core.SqlBuilders.SqlQueryCountBuilder<TEntity> instance and returns the result as a long.

public static long Get<TEntity>(this SqlQueryCountBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryCountBuilder<TEntity>

The IceCoffee.Db4Net.Core.SqlBuilders.SqlQueryCountBuilder<TEntity> instance containing the SQL query to execute.

transaction IDbTransaction

An optional IDbTransaction to associate with the query execution. If null, no transaction is used.

commandTimeout int?

An optional timeout value, in seconds, for the command execution. If null, the default timeout is used.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete. Defaults to None.

Returns

long

The result of the SQL query execution as a long.

Type Parameters

TEntity

The type of the entity associated with the SQL query.

Remarks

This method executes the SQL query defined in the sqlBuilder and retrieves the result using the provided database connection. If a transaction is specified, the query is executed within the context of that transaction.

Get<TEntity>(SqlQueryExistsBuilder<TEntity>, IDbTransaction?, bool, int?, CancellationToken)

Executes the SQL query built by the IceCoffee.Db4Net.Core.SqlBuilders.SqlQueryExistsBuilder<TEntity> and returns a boolean indicating whether the query result satisfies the condition.

public static bool Get<TEntity>(this SqlQueryExistsBuilder<TEntity> sqlBuilder, IDbTransaction? transaction = null, bool buffered = true, int? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

sqlBuilder SqlQueryExistsBuilder<TEntity>

The IceCoffee.Db4Net.Core.SqlBuilders.SqlQueryExistsBuilder<TEntity> instance containing the SQL query to execute.

transaction IDbTransaction

An optional IDbTransaction to associate with the query execution. If null, a new database connection is created.

buffered bool

A value indicating whether the query results should be buffered. If true, results are fully loaded into memory; otherwise, results are streamed.

commandTimeout int?

An optional timeout value, in seconds, for the command execution. If null, the default timeout is used.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

bool

true if the query result satisfies the condition; otherwise, false.

Type Parameters

TEntity