Example #1
0
 /// <summary>
 /// <para>Executes the <paramref name="command"/> and returns an <see cref="IDataReader"></see> through which the result can be read.
 /// It is the responsibility of the caller to close the reader when finished.</para>
 /// </summary>
 /// <param name="command">
 /// <para>The command that contains the query to execute.</para>
 /// </param>
 /// <returns>
 /// <para>An <see cref="IDataReader"/> object.</para>
 /// </returns>
 public virtual IDataReader ExecuteReader(DbCommand command)
 {
     using (DatabaseConnectionWrapper wrapper = this.GetOpenConnection())
     {
         PrepareCommand(command, wrapper.Connection);
         IDataReader realReader = this.DoExecuteReader(command, CommandBehavior.Default);
         return(this.CreateWrappedReader(wrapper, realReader));
     }
 }
Example #2
0
 /// <summary>
 /// All data readers get wrapped in objects so that they properly manage connections.
 /// Some derived Database classes will need to create a different wrapper, so this
 /// method is provided so that they can do this.
 /// </summary>
 /// <param name="connection">Connection + refcount.</param>
 /// <param name="innerReader">The reader to wrap.</param>
 /// <returns>The new reader.</returns>
 protected virtual IDataReader CreateWrappedReader(DatabaseConnectionWrapper connection, IDataReader innerReader)
 {
     return(new RefCountingDataReader(connection, innerReader));
 }
Example #3
0
        /// <summary>
        ///		Gets a "wrapped" connection that will be not be disposed if a transaction is
        ///		active (created by creating a TransactionScope instance). The
        ///		connection will be disposed when no transaction is active.
        /// </summary>
        /// <returns>Database connection wrapper.</returns>
        protected DatabaseConnectionWrapper GetOpenConnection()
        {
            DatabaseConnectionWrapper connection = TransactionScopeConnections.GetConnection(this);

            return(connection ?? this.GetWrappedConnection());
        }