Class DatabaseConnection
Database Connection
Namespace: Gossip.Connection
Assembly: Gossip.dll
Syntax
public class DatabaseConnection : object, IDatabaseConnection, IDisposable
Constructors
| Improve this Doc View SourceDatabaseConnection(ISqlConnection, Int32, IQueryExecutorProvider, CancellationToken)
Database Connection constructor
Declaration
public DatabaseConnection(ISqlConnection conn, int commandTimeout, IQueryExecutorProvider queryExecutorProvider, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| ISqlConnection | conn | Database connection |
| Int32 | commandTimeout | Database Command Timeout |
| IQueryExecutorProvider | queryExecutorProvider | Query executor |
| CancellationToken | cancellationToken | Cancellation token |
Methods
| Improve this Doc View SourceBeginTransaction()
Declaration
public ITransaction BeginTransaction()
Returns
| Type | Description |
|---|---|
| ITransaction |
BeginTransaction(System.Data.IsolationLevel)
Declaration
public ITransaction BeginTransaction(System.Data.IsolationLevel isolationLevel)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Data.IsolationLevel | isolationLevel |
Returns
| Type | Description |
|---|---|
| ITransaction |
BeginTransaction(System.Data.IsolationLevel, String)
Declaration
public ITransaction BeginTransaction(System.Data.IsolationLevel isolationLevel, string transactionName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Data.IsolationLevel | isolationLevel | |
| String | transactionName |
Returns
| Type | Description |
|---|---|
| ITransaction |
BeginTransaction(String)
Declaration
public ITransaction BeginTransaction(string transactionName)
Parameters
| Type | Name | Description |
|---|---|---|
| String | transactionName |
Returns
| Type | Description |
|---|---|
| ITransaction |
Configure(String, String)
Configures the database
Declaration
public IQueryConfigurator Configure(string callerMemberName = "", string callerFilePath = "")
Parameters
| Type | Name | Description |
|---|---|---|
| String | callerMemberName | (internal use) for logging |
| String | callerFilePath | (internal use) for logging |
Returns
| Type | Description |
|---|---|
| IQueryConfigurator | IQueryConfigurator |
Dispose()
Declaration
public void Dispose()
EnlistTransaction(Transaction)
Enlist a transaction
Declaration
public void EnlistTransaction(Transaction transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| Transaction | transaction | transaction |
Execute(String, Object, String, String)
Execute parameterized SQL.
Declaration
public int Execute(string sql, object param = null, string callerMemberName = "", string callerFilePath = "")
Parameters
| Type | Name | Description |
|---|---|---|
| String | sql | The SQL to execute for this query. |
| Object | param | The parameters to use for this query. |
| String | callerMemberName | (internal use) for logging |
| String | callerFilePath | (internal use) for logging |
Returns
| Type | Description |
|---|---|
| Int32 | The number of rows affected. |
ExecuteAsync(String, Object, String, String)
Execute parameterized SQL.
Declaration
public Task<int> ExecuteAsync(string sql, object param = null, string callerMemberName = "", string callerFilePath = "")
Parameters
| Type | Name | Description |
|---|---|---|
| String | sql | SQL query to run |
| Object | param | Parameters to pass into the SQL query |
| String | callerMemberName | Caller name |
| String | callerFilePath | Caller location |
Returns
| Type | Description |
|---|---|
| Task<Int32> | Integer number of rows affected |
Query<T>(String, Object, String, String)
Execute parameterized sql
Declaration
public IEnumerable<T> Query<T>(string sql, object param = null, string callerMemberName = "", string callerFilePath = "")
Parameters
| Type | Name | Description |
|---|---|---|
| String | sql | The SQL to execute for this query. |
| Object | param | The parameters to use for this query. |
| String | callerMemberName | (internal use) for logging |
| String | callerFilePath | (internal use) for logging |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | Result of the sql query, a collection of type T |
Type Parameters
| Name | Description |
|---|---|
| T | generic type |
QueryAsync<T>(String, Object, String, String)
Execute parameterized SQL.
Declaration
public Task<IEnumerable<T>> QueryAsync<T>(string sql, object param = null, string callerMemberName = "", string callerFilePath = "")
Parameters
| Type | Name | Description |
|---|---|---|
| String | sql | SQL query to run |
| Object | param | Parameters to pass into the SQL query |
| String | callerMemberName | (internal use) for logging |
| String | callerFilePath | (internal use) for logging |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<T>> | SQL query result |
Type Parameters
| Name | Description |
|---|---|
| T | Generic return type |
QueryFirstOrDefaultAsync<T>(String, Object, String, String)
Executes Parameterized SQL
Declaration
public Task<T> QueryFirstOrDefaultAsync<T>(string sql, object param = null, string callerMemberName = "", string callerFilePath = "")
Parameters
| Type | Name | Description |
|---|---|---|
| String | sql | The SQL to execute for this query. |
| Object | param | The parameters to use for this query. |
| String | callerMemberName | (internal use) for logging |
| String | callerFilePath | (internal use) for logging |
Returns
| Type | Description |
|---|---|
| Task<T> | The first result of the sql query |
Type Parameters
| Name | Description |
|---|---|
| T | Generic Type |
QuerySingleOrDefault<T>(String, String, String)
Executes SQL
Declaration
public T QuerySingleOrDefault<T>(string sql, string callerMemberName = "", string callerFilePath = "")
Parameters
| Type | Name | Description |
|---|---|---|
| String | sql | The SQL to execute for this query. |
| String | callerMemberName | (internal use) for logging |
| String | callerFilePath | (internal use) for logging |
Returns
| Type | Description |
|---|---|
| T | The first result of the sql query |
Type Parameters
| Name | Description |
|---|---|
| T | Generic Type |
QuerySingleOrDefaultAsync<T>(String, String, String)
Execute sql
Declaration
public Task<T> QuerySingleOrDefaultAsync<T>(string sql, string callerMemberName = "", string callerFilePath = "")
Parameters
| Type | Name | Description |
|---|---|---|
| String | sql | The SQL to execute for this query. |
| String | callerMemberName | (internal use) for logging |
| String | callerFilePath | (internal use) for logging |
Returns
| Type | Description |
|---|---|
| Task<T> | Result of the sql query, a collection of type T |
Type Parameters
| Name | Description |
|---|---|
| T | generic type |