コード例 #1
0
 /// <summary>
 /// Executes the given DbCommand and returns the result of the dataReaderHandler
 /// function delegate.  It will be given the DataReader and after its execution,
 /// the DataReader will be destroyed. This prevents from caller to have an active
 /// DataReader where they can leave a connection open. If there are errors in the
 /// delegate functions, the datareader is still closed.
 /// If a DbException is raised and a logger class had been provided,
 /// the method will attempt to Log a debug text version of the dbCommand
 /// that is backend specific or just log the exception.
 /// In either case, the exception will be thrown.
 /// </summary>
 /// <param name="dbCommand">Database Command Object to execute.</param>
 /// <param name="dataReaderHandler">A caller supplied delegate which will be called to consume the DataReader.</param>
 /// <returns>Returns the result of the DataReaderConsumerFunction.</returns>
 public T ConsumeReader <T>(DbCommand dbCommand
                            , Func <DbDataReader, T> dataReaderHandler)
 {
     try
     {
         using (DbDataReader dbRdr = (DbDataReader)ExecuteReader(dbCommand))
         {
             return((T)dataReaderHandler(dbRdr));
         }
     }
     catch (Exception e)
     {
         // create a new exception event object and log it when loggingMgr is available
         // always throw new event to caller.
         throw _daMgr.CreateAndLogExceptionEvent(e, dbCommand);
     }
 }