Exemple #1
0
        /// <summary>
        /// Executes a command, returning a data reader, against a data source.
        /// This method DOES NOT DISPOSE OF CONNECTION/TRANSACTION - UP TO THE CALLER.
        /// This method DOES NOT DISPOSE OF DATA READER - UP TO THE CALLER.
        /// </summary>
        /// <param name="dbConnection"> The database connection. </param>
        /// <param name="dbTransaction"> An optional local database transaction. </param>
        /// <param name="commandType"> The type of the command. </param>
        /// <param name="commandText"> The SQL text or stored procedure name. </param>
        /// <param name="commandParameters"> The parameters to use during the operation. </param>
        /// <param name="commandBehavior"> The reader behavior. </param>
        /// <param name="commandTimeout"> The command timeout (use null for default). </param>
        /// <param name="commandPrepare"> Whether to prepare the command at the data source. </param>
        /// <returns> The data reader result. </returns>
        public IDataReader ExecuteReader(IDbConnection dbConnection, IDbTransaction dbTransaction, CommandType commandType, string commandText, IEnumerable <IDbDataParameter> commandParameters, CommandBehavior commandBehavior, int?commandTimeout, bool commandPrepare)
        {
            IDataReader dataReader;

            OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::ExecuteReader(...): enter", typeof(AdoNetYieldingFascade).Name));

            if ((object)dbConnection == null)
            {
                throw new ArgumentNullException("dbConnection");
            }

            using (IDbCommand dbCommand = dbConnection.CreateCommand())
            {
                dbCommand.Transaction = dbTransaction;
                dbCommand.CommandType = commandType;
                dbCommand.CommandText = commandText;

                if ((object)commandTimeout != null)
                {
                    dbCommand.CommandTimeout = (int)commandTimeout;
                }

                // add parameters
                if ((object)commandParameters != null)
                {
                    foreach (IDbDataParameter commandParameter in commandParameters)
                    {
                        if ((object)commandParameter.Value == null)
                        {
                            commandParameter.Value = DBNull.Value;
                        }

                        dbCommand.Parameters.Add(commandParameter);
                    }
                }

                if (commandPrepare)
                {
                    dbCommand.Prepare();
                }

                // do the database work
                dataReader = dbCommand.ExecuteReader(commandBehavior);

                // wrap reader with proxy
                dataReader = new WrappedDataReader(dataReader);

                // clean out parameters
                //dbCommand.Parameters.Clear();

                OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::ExecuteReader(...): return reader", typeof(AdoNetYieldingFascade).Name));

                return(dataReader);
            }
        }
        /// <summary>
        /// Executes a command, returning a data reader, against a data source.
        /// This method DOES NOT DISPOSE OF CONNECTION/TRANSACTION - UP TO THE CALLER.
        /// This method DOES NOT DISPOSE OF DATA READER - UP TO THE CALLER.
        /// </summary>
        /// <param name="dbConnection"> The database connection. </param>
        /// <param name="dbTransaction"> An optional local database transaction. </param>
        /// <param name="commandType"> The type of the command. </param>
        /// <param name="commandText"> The SQL text or stored procedure name. </param>
        /// <param name="commandParameters"> The parameters to use during the operation. </param>
        /// <param name="commandBehavior"> The reader behavior. </param>
        /// <param name="commandTimeout"> The command timeout (use null for default). </param>
        /// <param name="commandPrepare"> Whether to prepare the command at the data source. </param>
        /// <returns> The data reader result. </returns>
        public IDataReader ExecuteReader(IDbConnection dbConnection, IDbTransaction dbTransaction, CommandType commandType, string commandText, IEnumerable<IDbDataParameter> commandParameters, CommandBehavior commandBehavior, int? commandTimeout, bool commandPrepare)
        {
            IDataReader dataReader;

            OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::ExecuteReader(...): enter", typeof(AdoNetYieldingFascade).Name));

            if ((object)dbConnection == null)
                throw new ArgumentNullException("dbConnection");

            using (IDbCommand dbCommand = dbConnection.CreateCommand())
            {
                dbCommand.Transaction = dbTransaction;
                dbCommand.CommandType = commandType;
                dbCommand.CommandText = commandText;

                if ((object)commandTimeout != null)
                    dbCommand.CommandTimeout = (int)commandTimeout;

                // add parameters
                if ((object)commandParameters != null)
                {
                    foreach (IDbDataParameter commandParameter in commandParameters)
                    {
                        if ((object)commandParameter.Value == null)
                            commandParameter.Value = DBNull.Value;

                        dbCommand.Parameters.Add(commandParameter);
                    }
                }

                if (commandPrepare)
                    dbCommand.Prepare();

                // do the database work
                dataReader = dbCommand.ExecuteReader(commandBehavior);

                // wrap reader with proxy
                dataReader = new WrappedDataReader(dataReader);

                // clean out parameters
                //dbCommand.Parameters.Clear();

                OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::ExecuteReader(...): return reader", typeof(AdoNetYieldingFascade).Name));

                return dataReader;
            }
        }