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
sqlBuilderISqlInsertAndGetIdBuilderAn instance of IceCoffee.Db4Net.Core.SqlBuilders.ISqlInsertAndGetIdBuilder.
transactionIDbTransactionAn optional database transaction.
bufferedboolSpecifies whether results are buffered.
commandTimeoutint?The command timeout in seconds.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<TId>
A task representing the asynchronous operation, with the new identity value.
Type Parameters
TIdThe 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
sqlBuilderSqlDeleteBuilder<TEntity>An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlDeleteBuilder<TEntity> containing the delete command.
transactionIDbTransactionThe optional database transaction to enlist in.
bufferedboolIndicates whether the query results should be buffered.
commandTimeoutint?An optional timeout in seconds for the command.
cancellationTokenCancellationTokenA 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
TEntityThe 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
sqlBuilderSqlDeleteEntityBuilder<TEntity>An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlDeleteEntityBuilder<TEntity> containing the delete command.
transactionIDbTransactionThe optional database transaction to enlist in.
bufferedboolIndicates whether the query results should be buffered.
commandTimeoutint?An optional timeout in seconds for the command.
cancellationTokenCancellationTokenA 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
TEntityThe 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
sqlBuilderSqlInsertBuilder<TEntity>An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertBuilder<TEntity>.
transactionIDbTransactionAn optional database transaction.
bufferedboolSpecifies whether results are buffered.
commandTimeoutint?The command timeout in seconds.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
Type Parameters
TEntityThe 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
sqlBuilderSqlInsertEntityBuilder<TEntity>An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertEntityBuilder<TEntity>.
transactionIDbTransactionAn optional database transaction.
bufferedboolSpecifies whether results are buffered.
commandTimeoutint?The command timeout in seconds.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
Type Parameters
TEntityThe 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
sqlBuilderSqlInsertOrIgnoreBuilder<TEntity>An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertOrIgnoreBuilder<TEntity>.
transactionIDbTransactionAn optional database transaction.
bufferedboolSpecifies whether results are buffered.
commandTimeoutint?The command timeout in seconds.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
Type Parameters
TEntityThe 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
sqlBuilderSqlInsertOrReplaceBuilder<TEntity>An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertOrReplaceBuilder<TEntity>.
transactionIDbTransactionAn optional database transaction.
bufferedboolSpecifies whether results are buffered.
commandTimeoutint?The command timeout in seconds.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
Type Parameters
TEntityThe 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
sqlBuilderSqlUpdateBuilder<TEntity>The IceCoffee.Db4Net.Core.SqlBuilders.SqlUpdateBuilder<TEntity> instance that defines the update operation.
transactionIDbTransactionThe database transaction to use for this command. (Optional)
bufferedboolA value indicating whether the command should be buffered. (Optional, defaults to true)
commandTimeoutint?The time in seconds to wait for the command to execute. (Optional)
cancellationTokenCancellationTokenA 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
TEntityThe 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
sqlBuilderSqlUpdateEntityBuilder<TEntity>The IceCoffee.Db4Net.Core.SqlBuilders.SqlUpdateEntityBuilder<TEntity> instance that defines the update operation.
transactionIDbTransactionThe database transaction to use for this command. (Optional)
bufferedboolA value indicating whether the command should be buffered. (Optional, defaults to true)
commandTimeoutint?The time in seconds to wait for the command to execute. (Optional)
cancellationTokenCancellationTokenA 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
TEntityThe 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
sqlBuilderISqlInsertAndGetIdBuilderAn instance of IceCoffee.Db4Net.Core.SqlBuilders.ISqlInsertAndGetIdBuilder.
transactionIDbTransactionAn optional database transaction.
bufferedboolSpecifies whether results are buffered.
commandTimeoutint?The command timeout in seconds.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- TId
The identity value of the inserted record.
Type Parameters
TIdThe 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
sqlBuilderSqlDeleteBuilder<TEntity>An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlDeleteBuilder<TEntity> containing the delete command.
transactionIDbTransactionThe optional database transaction to enlist in.
bufferedboolIndicates whether the query results should be buffered.
commandTimeoutint?An optional timeout in seconds for the command.
cancellationTokenCancellationTokenA token that may be used to cancel the operation.
Returns
- int
The number of rows affected by the DELETE operation.
Type Parameters
TEntityThe 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
sqlBuilderSqlDeleteEntityBuilder<TEntity>An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlDeleteEntityBuilder<TEntity> containing the delete command.
transactionIDbTransactionThe optional database transaction to enlist in.
bufferedboolIndicates whether the query results should be buffered.
commandTimeoutint?An optional timeout in seconds for the command.
cancellationTokenCancellationTokenA token that may be used to cancel the operation.
Returns
- int
The number of rows affected by the DELETE operation.
Type Parameters
TEntityThe 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
sqlBuilderSqlInsertBuilder<TEntity>An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertBuilder<TEntity>.
transactionIDbTransactionAn optional database transaction.
bufferedboolSpecifies whether results are buffered.
commandTimeoutint?The command timeout in seconds.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- int
The number of rows affected.
Type Parameters
TEntityThe 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
sqlBuilderSqlInsertEntityBuilder<TEntity>An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertEntityBuilder<TEntity>.
transactionIDbTransactionAn optional database transaction.
bufferedboolSpecifies whether results are buffered.
commandTimeoutint?The command timeout in seconds.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- int
The number of rows affected.
Type Parameters
TEntityThe 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
sqlBuilderSqlInsertOrIgnoreBuilder<TEntity>An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertOrIgnoreBuilder<TEntity>.
transactionIDbTransactionAn optional database transaction.
bufferedboolSpecifies whether results are buffered.
commandTimeoutint?The command timeout in seconds.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- int
The number of rows affected.
Type Parameters
TEntityThe 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
sqlBuilderSqlInsertOrReplaceBuilder<TEntity>An instance of IceCoffee.Db4Net.Core.SqlBuilders.SqlInsertOrReplaceBuilder<TEntity>.
transactionIDbTransactionAn optional database transaction.
bufferedboolSpecifies whether results are buffered.
commandTimeoutint?The command timeout in seconds.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- int
The number of rows affected.
Type Parameters
TEntityThe 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
sqlBuilderSqlUpdateBuilder<TEntity>The IceCoffee.Db4Net.Core.SqlBuilders.SqlUpdateBuilder<TEntity> instance that defines the update operation.
transactionIDbTransactionThe database transaction to use for this command. (Optional)
bufferedboolA value indicating whether the command should be buffered. (Optional, defaults to true)
commandTimeoutint?The time in seconds to wait for the command to execute. (Optional)
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the operation. (Optional)
Returns
- int
The number of rows affected.
Type Parameters
TEntityThe 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
sqlBuilderSqlUpdateEntityBuilder<TEntity>The IceCoffee.Db4Net.Core.SqlBuilders.SqlUpdateEntityBuilder<TEntity> instance that defines the update operation.
transactionIDbTransactionThe database transaction to use for this command. (Optional)
bufferedboolA value indicating whether the command should be buffered. (Optional, defaults to true)
commandTimeoutint?The time in seconds to wait for the command to execute. (Optional)
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the operation. (Optional)
Returns
- int
The number of rows affected.
Type Parameters
TEntityThe 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
sqlBuilderSqlQueryExistsBuilderThe exists SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query result is buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe 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
sqlBuilderSqlQueryExistsBuilderThe exists SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query result is buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe 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
sqlBuilderISqlQueryCountBuilderThe SQL query builder that defines the query to execute.
transactionIDbTransactionAn optional database transaction to associate with the query execution. If null, a new connection is created.
commandTimeoutint?An optional timeout value, in seconds, for the query execution. If null, the default timeout is used.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- Task<T>
A task representing the asynchronous operation. The task result contains the value of type
Tretrieved from the query. If no value is found, the result is null.
Type Parameters
TThe 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
sqlBuilderSqlQueryCountBuilder<TEntity>The IceCoffee.Db4Net.Core.SqlBuilders.SqlQueryCountBuilder<TEntity> instance containing the SQL query and its parameters.
transactionIDbTransactionAn optional IDbTransaction to associate with the query execution. If null, a new database connection is created.
commandTimeoutint?An optional timeout value, in seconds, for the command execution. If null, the default timeout is used.
cancellationTokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
Type Parameters
TEntityThe 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
sqlBuilderSqlQueryExistsBuilder<TEntity>The IceCoffee.Db4Net.Core.SqlBuilders.SqlQueryExistsBuilder<TEntity> instance used to construct the SQL query.
transactionIDbTransactionAn optional IDbTransaction to associate with the query execution. If null, the query will execute without a transaction.
bufferedboolIndicates whether the query results should be buffered. Set to true to enable buffering; otherwise, false.
commandTimeoutint?An optional timeout value, in seconds, for the command execution. If null, the default timeout is used.
cancellationTokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
Type Parameters
TEntityThe 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
sqlBuilderSqlQueryBuilderThe SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<T>
A task that represents the asynchronous operation. The task result contains the first record of type T.
Type Parameters
TThe 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
sqlBuilderSqlQueryBuilder<TEntity>The SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TEntity>
A task that represents the asynchronous operation. The task result contains the first record of type TEntity.
Type Parameters
TEntityThe 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
sqlBuilderSqlQueryBuilderThe SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe 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
TThe 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
sqlBuilderSqlQueryBuilder<TEntity>The SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe 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
TEntityThe 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
sqlBuilderSqlQueryBuilderThe SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- T
The first record of type T or default if not found.
Type Parameters
TThe 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
sqlBuilderSqlQueryBuilder<TEntity>The SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- TEntity
The first record of type TEntity or default if not found.
Type Parameters
TEntityThe 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
sqlBuilderSqlQueryBuilderThe SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- T
The first record of type T.
Type Parameters
TThe 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
sqlBuilderSqlQueryBuilder<TEntity>The SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- TEntity
The first record of type TEntity.
Type Parameters
TEntityThe 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
sqlBuilderSqlQueryBuilderThe SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe 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
TThe 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
sqlBuilderSqlQueryBuilder<TEntity>The SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe 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
TEntityThe 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
sqlBuilderSqlQueryPagedBuilderThe paged SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe 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
TThe 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
sqlBuilderSqlQueryPagedBuilder<TEntity>The paged SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe 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
TEntityThe 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
sqlBuilderSqlQueryStoredProcedureBuilderThe stored procedure query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe 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
TThe 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
sqlBuilderSqlQueryStoredProcedureBuilder<TEntity>The stored procedure query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe 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
TEntityThe 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
sqlBuilderSqlQueryBuilderThe SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- IEnumerable<T>
An enumerable collection of records of type T.
Type Parameters
TThe 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
sqlBuilderSqlQueryBuilder<TEntity>The SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- IEnumerable<TEntity>
An enumerable collection of records of type TEntity.
Type Parameters
TEntityThe 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
sqlBuilderSqlQueryPagedBuilderThe paged SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- IEnumerable<T>
An enumerable collection of records of type T.
Type Parameters
TThe 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
sqlBuilderSqlQueryPagedBuilder<TEntity>The paged SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- IEnumerable<TEntity>
An enumerable collection of records of type TEntity.
Type Parameters
TEntityThe 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
sqlBuilderSqlQueryStoredProcedureBuilderThe stored procedure query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- IEnumerable<T>
An enumerable collection of records of type T.
Type Parameters
TThe 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
sqlBuilderSqlQueryStoredProcedureBuilder<TEntity>The stored procedure query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- IEnumerable<TEntity>
An enumerable collection of records of type TEntity.
Type Parameters
TEntityThe 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
sqlBuilderSqlQueryPagedBuilderThe paged SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe 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
TThe 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
sqlBuilderSqlQueryPagedBuilder<TEntity>The paged SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe 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
TEntityThe 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
sqlBuilderSqlQueryPagedBuilderThe paged SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- PagedResult<T>
A paged result containing the total count and a collection of records of type T.
Type Parameters
TThe 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
sqlBuilderSqlQueryPagedBuilder<TEntity>The paged SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- PagedResult<TEntity>
A paged result containing the total count and a collection of records of type TEntity.
Type Parameters
TEntityThe 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
sqlBuilderSqlQueryBuilderThe SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<T>
A task that represents the asynchronous operation. The task result contains a single record of type T.
Type Parameters
TThe 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
sqlBuilderSqlQueryBuilder<TEntity>The SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TEntity>
A task that represents the asynchronous operation. The task result contains a single record of type TEntity.
Type Parameters
TEntityThe 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
sqlBuilderSqlQueryBuilderThe SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe 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
TThe 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
sqlBuilderSqlQueryBuilder<TEntity>The SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe 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
TEntityThe 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
sqlBuilderSqlQueryBuilderThe SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- T
A single record of type T or default if not found.
Type Parameters
TThe 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
sqlBuilderSqlQueryBuilder<TEntity>The SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- TEntity
A single record of type TEntity or default if not found.
Type Parameters
TEntityThe 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
sqlBuilderSqlQueryBuilderThe SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- T
A single record of type T.
Type Parameters
TThe 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
sqlBuilderSqlQueryBuilder<TEntity>The SQL query builder.
transactionIDbTransactionThe optional database transaction.
bufferedboolDetermines whether the query results are buffered.
commandTimeoutint?The optional command timeout.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- TEntity
A single record of type TEntity.
Type Parameters
TEntityThe 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
sqlBuilderISqlQueryCountBuilderThe SQL query builder that defines the query to execute.
transactionIDbTransactionAn optional database transaction to associate with the query execution. If null, the query will execute without a transaction.
commandTimeoutint?An optional timeout value, in seconds, for the command execution. If null, the default timeout is used.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- T
The scalar value of type
Tretrieved from the query execution, or null if the query result is empty.
Type Parameters
TThe 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
sqlBuilderSqlQueryCountBuilder<TEntity>The IceCoffee.Db4Net.Core.SqlBuilders.SqlQueryCountBuilder<TEntity> instance containing the SQL query to execute.
transactionIDbTransactionAn optional IDbTransaction to associate with the query execution. If null, no transaction is used.
commandTimeoutint?An optional timeout value, in seconds, for the command execution. If null, the default timeout is used.
cancellationTokenCancellationTokenA CancellationToken to observe while waiting for the task to complete. Defaults to None.
Returns
Type Parameters
TEntityThe 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
sqlBuilderSqlQueryExistsBuilder<TEntity>The IceCoffee.Db4Net.Core.SqlBuilders.SqlQueryExistsBuilder<TEntity> instance containing the SQL query to execute.
transactionIDbTransactionAn optional IDbTransaction to associate with the query execution. If null, a new database connection is created.
bufferedboolA value indicating whether the query results should be buffered. If true, results are fully loaded into memory; otherwise, results are streamed.
commandTimeoutint?An optional timeout value, in seconds, for the command execution. If null, the default timeout is used.
cancellationTokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
Type Parameters
TEntity