Interface ISqlConnection
Represents a SQL connection.
Namespace: Gossip.Connection.Fluent
Assembly: Gossip.dll
Syntax
public interface ISqlConnection : IDisposable
Methods
| Improve this Doc View SourceBeginTransaction()
Begin a transaction.
Declaration
ITransaction BeginTransaction()
Returns
| Type | Description |
|---|---|
| ITransaction |
BeginTransaction(System.Data.IsolationLevel)
Begin a transaction with a specified
Declaration
ITransaction BeginTransaction(System.Data.IsolationLevel isolationLevel)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Data.IsolationLevel | isolationLevel | The |
Returns
| Type | Description |
|---|---|
| ITransaction |
BeginTransaction(System.Data.IsolationLevel, String)
Begin a named transaction with a specified
Declaration
ITransaction BeginTransaction(System.Data.IsolationLevel isolationLevel, string transactionName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Data.IsolationLevel | isolationLevel | The |
| String | transactionName | The transaction name. |
Returns
| Type | Description |
|---|---|
| ITransaction |
BeginTransaction(String)
Begin a named transaction.
Declaration
ITransaction BeginTransaction(string transactionName)
Parameters
| Type | Name | Description |
|---|---|---|
| String | transactionName | The transaction name. |
Returns
| Type | Description |
|---|---|
| ITransaction |
BulkInsertAsync<T>(String, IEnumerable<T>, Int32, Action<Object, SqlRowsCopiedEventArgs>, Int32, Dictionary<String, String>, Int32)
Bulk insert data into a table.
Declaration
Task BulkInsertAsync<T>(string insertIntoTable, IEnumerable<T> data, int batchSize = 1000, Action<object, SqlRowsCopiedEventArgs> notifyCallback = null, int notifyAfter = 10000, Dictionary<string, string> columnMapping = null, int timeoutSeconds = 30)
Parameters
| Type | Name | Description |
|---|---|---|
| String | insertIntoTable | The name of the table. |
| IEnumerable<T> | data | The data to insert. |
| Int32 | batchSize | The size of the batches for bulk insert. |
| Action<Object, SqlRowsCopiedEventArgs> | notifyCallback | A callback to pass to |
| Int32 | notifyAfter | Occurs after each batch has been processed. |
| Dictionary<String, String> | columnMapping | A dictionary of column mappings. |
| Int32 | timeoutSeconds | The timeout, specified in seconds. |
Returns
| Type | Description |
|---|---|
| Task |
Type Parameters
| Name | Description |
|---|---|
| T | The type of data being bulk inserted. |
Close()
Synchronously close the SQL connection.
Declaration
void Close()
EnlistTransaction(Transaction)
Enlist the given transaction.
Declaration
void EnlistTransaction(Transaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| Transaction | transaction | The transaction to enlist. |
Execute(String, Object, Int32, CancellationToken, IDbTransaction)
Synchronously execute the query.
Declaration
int Execute(string query, object parameters, int commandTimeout, CancellationToken cancellationToken, IDbTransaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | The SQL to execute for this query. |
| Object | parameters | The parameters to use for this query. |
| Int32 | commandTimeout | Number of seconds before command execution timeout. |
| CancellationToken | cancellationToken | A cancellation token for cooperatively cancelling the operation. |
| IDbTransaction | transaction | The transaction to use for this query. |
Returns
| Type | Description |
|---|---|
| Int32 | The number of rows impacted by the query. |
ExecuteAsync(String, Object, Int32, CancellationToken, IDbTransaction)
Asynchronously execute the query.
Declaration
Task<int> ExecuteAsync(string query, object parameters, int commandTimeout, CancellationToken cancellationToken, IDbTransaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | The SQL to execute for this query. |
| Object | parameters | The parameters to use for this query. |
| Int32 | commandTimeout | Number of seconds before command execution timeout. |
| CancellationToken | cancellationToken | A cancellation token for cooperatively cancelling the operation. |
| IDbTransaction | transaction | The transaction to use for this query. |
Returns
| Type | Description |
|---|---|
| Task<Int32> | The number of rows impacted by the query. |
ExecuteScalar<T>(String, Object, Int32, IDbTransaction)
Synchronously execute the query and return a single value.
Declaration
T ExecuteScalar<T>(string query, object parameters, int commandTimeout, IDbTransaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | The SQL to execute for this query. |
| Object | parameters | The parameters to use for this query. |
| Int32 | commandTimeout | Number of seconds before command execution timeout. |
| IDbTransaction | transaction | The transaction to use for this query. |
Returns
| Type | Description |
|---|---|
| T | A single |
Type Parameters
| Name | Description |
|---|---|
| T | The type of data to return. |
ExecuteScalarAsync<T>(String, Object, Int32, CancellationToken, IDbTransaction)
Synchronously execute the query and return a single value.
Declaration
Task<T> ExecuteScalarAsync<T>(string query, object parameters, int commandTimeout, CancellationToken cancellationToken, IDbTransaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | The SQL to execute for this query. |
| Object | parameters | The parameters to use for this query. |
| Int32 | commandTimeout | Number of seconds before command execution timeout. |
| CancellationToken | cancellationToken | A cancellation token for cooperatively cancelling the operation. |
| IDbTransaction | transaction | The transaction to use for this query. |
Returns
| Type | Description |
|---|---|
| Task<T> | A single |
Type Parameters
| Name | Description |
|---|---|
| T | The type of data to return. |
GetConnectionDetails()
Get the connection details such as the server and database name.
Declaration
IConnectionDetails GetConnectionDetails()
Returns
| Type | Description |
|---|---|
| IConnectionDetails | The IConnectionDetails. |
Open()
Synchronously open the SQL connection.
Declaration
void Open()
OpenAsync(CancellationToken)
Asynchronously open the SQL connection.
Declaration
Task OpenAsync(CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | A cancellation token for cooperatively cancelling the operation. |
Returns
| Type | Description |
|---|---|
| Task |
Query<T>(String, Object, Int32, Boolean, IDbTransaction)
Synchronously execute the query and return the results.
Declaration
IEnumerable<T> Query<T>(string query, object parameters, int commandTimeout, bool buffered, IDbTransaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | The query to execute. |
| Object | parameters | The parameters for the query. |
| Int32 | commandTimeout | The effective timeout for the command. |
| Boolean | buffered | Whether to buffer the results in memory or not. |
| IDbTransaction | transaction | An |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | The |
Type Parameters
| Name | Description |
|---|---|
| T | The type of results to return. |
QueryAsync<T>(String, Object, Int32, CancellationToken, IDbTransaction)
Asynchronously execute the query and return the results.
Declaration
Task<IEnumerable<T>> QueryAsync<T>(string query, object parameters, int commandTimeout, CancellationToken cancellationToken, IDbTransaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | The query to execute. |
| Object | parameters | The parameters for the query. |
| Int32 | commandTimeout | The effective timeout for the command. |
| CancellationToken | cancellationToken | A cancellation token to cooperatively cancel the operation. |
| IDbTransaction | transaction | An |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<T>> | The |
Type Parameters
| Name | Description |
|---|---|
| T | The type of results to return. |
QueryAsync<TFirst, TSecond, TReturn>(String, Func<TFirst, TSecond, TReturn>, Object, Int32, IDbTransaction)
Perform a asynchronous multi-mapping query with 2 input types.
This returns a single type, combined from the raw types via mapping.
Declaration
Task<IEnumerable<TReturn>> QueryAsync<TFirst, TSecond, TReturn>(string query, Func<TFirst, TSecond, TReturn> mapping, object parameters, int commandTimeout, IDbTransaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | The SQL to execute for this query. |
| Func<TFirst, TSecond, TReturn> | mapping | The function to map row types to the return type. |
| Object | parameters | The parameters to use for this query. |
| Int32 | commandTimeout | Number of seconds before command execution timeout. |
| IDbTransaction | transaction | The transaction to use for this query. |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<TReturn>> | An enumerable of |
Type Parameters
| Name | Description |
|---|---|
| TFirst | The first type in the recordset. |
| TSecond | The second type in the recordset. |
| TReturn | The combined type to return. |
QueryAsync<TFirst, TSecond, TThird, TReturn>(String, Func<TFirst, TSecond, TThird, TReturn>, Object, Int32, IDbTransaction)
Perform a asynchronous multi-mapping query with 3 input types.
This returns a single type, combined from the raw types via mapping.
Declaration
Task<IEnumerable<TReturn>> QueryAsync<TFirst, TSecond, TThird, TReturn>(string query, Func<TFirst, TSecond, TThird, TReturn> mapping, object parameters, int commandTimeout, IDbTransaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | The SQL to execute for this query. |
| Func<TFirst, TSecond, TThird, TReturn> | mapping | The function to map row types to the return type. |
| Object | parameters | The parameters to use for this query. |
| Int32 | commandTimeout | Number of seconds before command execution timeout. |
| IDbTransaction | transaction | The transaction to use for this query. |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<TReturn>> | An enumerable of |
Type Parameters
| Name | Description |
|---|---|
| TFirst | The first type in the recordset. |
| TSecond | The second type in the recordset. |
| TThird | The third type in the recordset. |
| TReturn | The combined type to return. |
QueryAsync<TFirst, TSecond, TThird, TFourth, TReturn>(String, Func<TFirst, TSecond, TThird, TFourth, TReturn>, Object, Int32, IDbTransaction)
Perform a asynchronous multi-mapping query with 4 input types.
This returns a single type, combined from the raw types via mapping.
Declaration
Task<IEnumerable<TReturn>> QueryAsync<TFirst, TSecond, TThird, TFourth, TReturn>(string query, Func<TFirst, TSecond, TThird, TFourth, TReturn> mapping, object parameters, int commandTimeout, IDbTransaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | The SQL to execute for this query. |
| Func<TFirst, TSecond, TThird, TFourth, TReturn> | mapping | The function to map row types to the return type. |
| Object | parameters | The parameters to use for this query. |
| Int32 | commandTimeout | Number of seconds before command execution timeout. |
| IDbTransaction | transaction | The transaction to use for this query. |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<TReturn>> | An enumerable of |
Type Parameters
| Name | Description |
|---|---|
| TFirst | The first type in the recordset. |
| TSecond | The second type in the recordset. |
| TThird | The third type in the recordset. |
| TFourth | The fourth type in the recordset. |
| TReturn | The combined type to return. |
QueryAsync<TFirst, TSecond, TThird, TFourth, TFifth, TReturn>(String, Func<TFirst, TSecond, TThird, TFourth, TFifth, TReturn>, Object, Int32, IDbTransaction)
Perform a asynchronous multi-mapping query with 5 input types.
This returns a single type, combined from the raw types via mapping.
Declaration
Task<IEnumerable<TReturn>> QueryAsync<TFirst, TSecond, TThird, TFourth, TFifth, TReturn>(string query, Func<TFirst, TSecond, TThird, TFourth, TFifth, TReturn> mapping, object parameters, int commandTimeout, IDbTransaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | The SQL to execute for this query. |
| Func<TFirst, TSecond, TThird, TFourth, TFifth, TReturn> | mapping | The function to map row types to the return type. |
| Object | parameters | The parameters to use for this query. |
| Int32 | commandTimeout | Number of seconds before command execution timeout. |
| IDbTransaction | transaction | The transaction to use for this query. |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<TReturn>> | An enumerable of |
Type Parameters
| Name | Description |
|---|---|
| TFirst | The first type in the recordset. |
| TSecond | The second type in the recordset. |
| TThird | The third type in the recordset. |
| TFourth | The fourth type in the recordset. |
| TFifth | The fifth type in the recordset. |
| TReturn | The combined type to return. |
QueryAsync<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TReturn>(String, Func<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TReturn>, Object, Int32, IDbTransaction)
Perform a asynchronous multi-mapping query with 6 input types.
This returns a single type, combined from the raw types via mapping.
Declaration
Task<IEnumerable<TReturn>> QueryAsync<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TReturn>(string query, Func<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TReturn> mapping, object parameters, int commandTimeout, IDbTransaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | The SQL to execute for this query. |
| Func<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TReturn> | mapping | The function to map row types to the return type. |
| Object | parameters | The parameters to use for this query. |
| Int32 | commandTimeout | Number of seconds before command execution timeout. |
| IDbTransaction | transaction | The transaction to use for this query. |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<TReturn>> | An enumerable of |
Type Parameters
| Name | Description |
|---|---|
| TFirst | The first type in the recordset. |
| TSecond | The second type in the recordset. |
| TThird | The third type in the recordset. |
| TFourth | The fourth type in the recordset. |
| TFifth | The fifth type in the recordset. |
| TSixth | The sixth type in the recordset. |
| TReturn | The combined type to return. |
QueryAsync<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(String, Func<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>, Object, Int32, IDbTransaction)
Perform a asynchronous multi-mapping query with 7 input types.
This returns a single type, combined from the raw types via mapping.
Declaration
Task<IEnumerable<TReturn>> QueryAsync<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(string query, Func<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn> mapping, object parameters, int commandTimeout, IDbTransaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | The SQL to execute for this query. |
| Func<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn> | mapping | The function to map row types to the return type. |
| Object | parameters | The parameters to use for this query. |
| Int32 | commandTimeout | Number of seconds before command execution timeout. |
| IDbTransaction | transaction | The transaction to use for this query. |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<TReturn>> |
Type Parameters
| Name | Description |
|---|---|
| TFirst | The first type in the recordset. |
| TSecond | The second type in the recordset. |
| TThird | The third type in the recordset. |
| TFourth | The fourth type in the recordset. |
| TFifth | The fifth type in the recordset. |
| TSixth | The sixth type in the recordset. |
| TSeventh | The seventh type in the recordset. |
| TReturn | The combined type to return. |
QueryFirstOrDefault<T>(String, Object, Int32, CancellationToken, IDbTransaction)
Synchronously query for the first result, or the default value of
Declaration
T QueryFirstOrDefault<T>(string query, object parameters, int commandTimeout, CancellationToken cancellationToken, IDbTransaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | The query to execute. |
| Object | parameters | The parameters for the query. |
| Int32 | commandTimeout | The effective timeout for the command. |
| CancellationToken | cancellationToken | A cancellation token to cooperatively cancel the operation. |
| IDbTransaction | transaction | An |
Returns
| Type | Description |
|---|---|
| T | The first result of the query, or the default value of |
Type Parameters
| Name | Description |
|---|---|
| T | The type of results to return. |
QueryFirstOrDefaultAsync<T>(String, Object, Int32, CancellationToken, IDbTransaction)
Asynchronously query for the first result, or the default value of
Declaration
Task<T> QueryFirstOrDefaultAsync<T>(string query, object parameters, int commandTimeout, CancellationToken cancellationToken, IDbTransaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | The query to execute. |
| Object | parameters | The parameters for the query. |
| Int32 | commandTimeout | The effective timeout for the command. |
| CancellationToken | cancellationToken | A cancellation token to cooperatively cancel the operation. |
| IDbTransaction | transaction | An |
Returns
| Type | Description |
|---|---|
| Task<T> | The first result of the query, or the default value of |
Type Parameters
| Name | Description |
|---|---|
| T | The type of results to return. |
QuerySingleOrDefault<T>(String, Object, Int32, CancellationToken, IDbTransaction)
Synchronously query for a single result, or the default value of
Declaration
T QuerySingleOrDefault<T>(string query, object parameters, int commandTimeout, CancellationToken cancellationToken, IDbTransaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | The query to execute. |
| Object | parameters | The parameters for the query. |
| Int32 | commandTimeout | The effective timeout for the command. |
| CancellationToken | cancellationToken | A cancellation token to cooperatively cancel the operation. |
| IDbTransaction | transaction | An |
Returns
| Type | Description |
|---|---|
| T | The result of the query, or the default value of |
Type Parameters
| Name | Description |
|---|---|
| T | The type of results to return. |
QuerySingleOrDefaultAsync<T>(String, Object, Int32, CancellationToken, IDbTransaction)
Asynchronously query for a single result, or the default value of
Declaration
Task<T> QuerySingleOrDefaultAsync<T>(string query, object parameters, int commandTimeout, CancellationToken cancellationToken, IDbTransaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | The query to execute. |
| Object | parameters | The parameters for the query. |
| Int32 | commandTimeout | The effective timeout for the command. |
| CancellationToken | cancellationToken | A cancellation token to cooperatively cancel the operation. |
| IDbTransaction | transaction | An |
Returns
| Type | Description |
|---|---|
| Task<T> | The result of the query, or the default value of |
Type Parameters
| Name | Description |
|---|---|
| T | The type of results to return. |