DbConnection Extensions
Extension class for database actions excluding querying (data reading).
namespace KLO128.D3ORM.Common.Extensions
{
public static class DbConectionExtensions
}
Assembly
KLO128.D3ORM.Common
Base Types
None
Properties
None
Methods
AttachTransaction
public static void AttachTransaction(this IDbConnection connection, IDbCommand cmd)
Description
Attaches connection's transaction to the cmd if accessible. MSSQL requires it.
Return Type
void
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
this | connection | IDbConnection | connection invoker | |
1. | cmd | IDbCommand | command which the transaction will be attached to |
ExecuteCommand
public static void ExecuteCommand(this IDbConnection connection, string cmdText, int? commandTimeout = null, params string[] parameters)
Description
Opens the connection if not opened, creates a non-query command using cmdText and pars, executes the command and disposes the command.
Return Type
void
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
this | connection | IDbConnection | connection invoker | |
1. | cmdText | string | command text | |
2. | commandTimeout | int? | command timeout (If null, then the default timeout is used.) | null |
params | parameters | string[] | command parameter values converted to string | string[0] |
ExecuteDbStoredCommand
public static void ExecuteDbStoredCommand(this IDbConnection connection, string cmdText, int? commandTimeout = null, params IDbDataParameter[] parameters)
Description
Executes a command as a stored procedure using cmdText and parameters. The connection is opened if not have been and the command is disposed after finishing the work.
Return Type
void
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
this | connection | IDbConnection | connection invoker | |
1. | cmdText | string | stored procedure name | |
2. | commandTimeout | int? | command timeout (If null, then the default timeout is used.) | null |
params | parameters | IDbDataParameter[] | stored procedure parameters | IDbDataParameter[0] |
OpenIfNot
public static void OpenIfNot(this IDbConnection connection)
Description
Opens the connection if not opened.
Return Type
void
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
this | connection | IDbConnection | connection invoker |