// use for buffered queries that do not return a type async Task IDatabaseConnectionFactory.GetConnection(Func <IDbConnection, Task> getData) { try { using (var connection = new CisCustomDbConnection(new SqlConnection(_connectionString), this._commandTimeout)) { await connection.OpenAsync(); await getData(connection); } } catch (TimeoutException ex) { throw new Exception(String.Format("{0}.GetConnection() experienced a SQL timeout", GetType().FullName), ex); } catch (SqlException ex) { throw new Exception(String.Format("{0}.GetConnection() experienced a SQL exception (not a timeout)", GetType().FullName), ex); } }
// use for non-buffered queries that return a type async Task <TResult> IDatabaseConnectionFactory.GetConnection <TRead, TResult>(Func <IDbConnection, Task <TRead> > getData, Func <TRead, Task <TResult> > process) { try { using (var connection = new CisCustomDbConnection(new SqlConnection(_connectionString), this._commandTimeout)) { await connection.OpenAsync(); var data = await getData(connection); return(await process(data)); } } catch (TimeoutException ex) { throw new Exception(String.Format("{0}.GetConnection() experienced a SQL timeout", GetType().FullName), ex); } catch (SqlException ex) { throw new Exception(String.Format("{0}.GetConnection() experienced a SQL exception (not a timeout)", GetType().FullName), ex); } }