Class DbDataSourceExtensions
Namespace: Momentum.Extensions.Data
Assembly: Momentum.Extensions.dll
public static class DbDataSourceExtensionsInheritance
object ← DbDataSourceExtensions
Inherited Members
object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Methods
SpCall<TResult>(DbDataSource, string, IDbParamsProvider, Func<DbConnection, Func<CommandDefinition, Task<TResult>>>, DbTransaction?, int?, CancellationToken)
Core method that opens a connection and executes a Dapper function via stored procedure.
public static Task<TResult> SpCall<TResult>(this DbDataSource dataSource, string spName, IDbParamsProvider parameters, Func<DbConnection, Func<CommandDefinition, Task<TResult>>> dbFunction, DbTransaction? transaction = null, int? commandTimeout = null, CancellationToken cancellationToken = default)Parameters
dataSource DbDataSource
The DbDataSource data source.
spName string
The name of the stored procedure.
parameters IDbParamsProvider
Provider for command parameters.
dbFunction Func<DbConnection, Func<CommandDefinition, Task<TResult>>>
Factory that returns a Dapper execution function for the given connection.
transaction DbTransaction?
Optional database transaction to associate with the command. If provided, it must originate from a connection obtained from the same dataSource, or the command will fail at runtime.
commandTimeout int?
Optional command timeout in seconds.
cancellationToken CancellationToken
Cancellation token.
Returns
Task<TResult>
The result of the Dapper function execution.
Type Parameters
TResult
SpExecute(DbDataSource, string, IDbParamsProvider, DbTransaction?, int?, CancellationToken)
Executes a stored procedure that returns the number of affected rows.
[ExcludeFromCodeCoverage]
public static Task<int> SpExecute(this DbDataSource dataSource, string spName, IDbParamsProvider parameters, DbTransaction? transaction = null, int? commandTimeout = null, CancellationToken cancellationToken = default)Parameters
dataSource DbDataSource
The DbDataSource data source.
spName string
The name of the stored procedure.
parameters IDbParamsProvider
Provider for command parameters.
transaction DbTransaction?
Optional database transaction to associate with the command.
commandTimeout int?
Optional command timeout in seconds.
cancellationToken CancellationToken
Cancellation token.
Returns
The number of affected rows.
SpQuery<TResult>(DbDataSource, string, IDbParamsProvider, DbTransaction?, int?, CancellationToken)
Query data using a stored procedure that returns a collection of TResult.
[ExcludeFromCodeCoverage]
public static Task<IEnumerable<TResult>> SpQuery<TResult>(this DbDataSource dataSource, string spName, IDbParamsProvider parameters, DbTransaction? transaction = null, int? commandTimeout = null, CancellationToken cancellationToken = default)Parameters
dataSource DbDataSource
The DbDataSource data source.
spName string
The name of the stored procedure.
parameters IDbParamsProvider
Provider for sp parameters.
transaction DbTransaction?
Optional database transaction to associate with the command.
commandTimeout int?
Optional command timeout in seconds.
cancellationToken CancellationToken
Cancellation token.
Returns
Task<IEnumerable<TResult>>
Collection of TResult
Type Parameters
TResult