public virtual T SelectOne <T>(string queryStr, FormatGenericData <T> genericDataDelegate) { T result = default(T); try { // Manually open connection so that connection does not // close after database transaction is performed. LazyOpenConnection(); using (DbCommand command = CreateDbCommand(queryStr)) using (DbDataReader reader = command.ExecuteReader()) { bool hasMultipleRows = false; while (reader.Read()) { if (hasMultipleRows) { throw new Exception("Cannot return more than one row in SelectOne()"); } result = genericDataDelegate(reader); hasMultipleRows = true; } } } catch (SqlException e) { PerformErrorLogging(this.ErrorLoggingDelegate, e); } catch (DbException e) { PerformErrorLogging(this.ErrorLoggingDelegate, e); } catch (Exception e) { PerformErrorLogging(this.ErrorLoggingDelegate, e); } finally { PerformKeepAliveCheck(); } return(result); }
public virtual List <T> SelectList <T>(string queryStr, FormatGenericData <T> genericDataDelegate, DbParameter[] parameters) { List <T> result = new List <T>(); try { // Manually open connection so that connection does not // close after database transaction is performed. LazyOpenConnection(); using (DbCommand command = CreateDbCommand(queryStr)) { command.Parameters.AddRange(parameters); using (DbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { result.Add(genericDataDelegate(reader)); } } } } catch (SqlException e) { PerformErrorLogging(this.ErrorLoggingDelegate, e); } catch (DbException e) { PerformErrorLogging(this.ErrorLoggingDelegate, e); } catch (Exception e) { PerformErrorLogging(this.ErrorLoggingDelegate, e); } finally { PerformKeepAliveCheck(); } return(result); }