示例#1
0
        /// <summary>
        /// Execute sql command and call function
        /// </summary>
        /// <returns>number of records affected</returns>
        public override int Execute()
        {
            SqlDataReader reader = null;

            try
            {
                reader = InternalCommand.ExecuteReader();
            }
            catch (SqlException ex)
            {
                throw new CommandException(InternalCommand, ex);
            }
            _RecordsAffected = reader.RecordsAffected;
            try
            {
                while (reader.Read() && _ReadFunc != null && _ReadFunc(reader).Result)
                {
                    ;
                }
            }
            finally
            {
                reader.Close();
            }
            if (_OnComplete != null)
            {
                _OnComplete(this, EventArgs.Empty);
            }
            return(_RecordsAffected);
        }
示例#2
0
        protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            DbDataReader originalResult = null;

            var context = NHProfilerContextProvider.GetLoggedDbCommand(InternalCommand, null);

            _profiler.ReaderExecuting(InternalCommand, context);
            _stopwatch.Restart();
            try
            {
                originalResult = InternalCommand.ExecuteReader(behavior);

                var dataSet = new DataSet {
                    EnforceConstraints = false
                };
                DataRows = new DataTable(tableName: Guid.NewGuid().ToString());
                dataSet.Tables.Add(DataRows);
                dataSet.Load(originalResult, LoadOption.OverwriteChanges, DataRows);

                originalResult = DataRows.CreateDataReader();
            }
            catch (Exception e)
            {
                context = NHProfilerContextProvider.GetLoggedDbCommand(InternalCommand, e);
                _profiler.ReaderExecuting(InternalCommand, context);
                throw;
            }
            finally
            {
                _stopwatch.Stop();
                context = NHProfilerContextProvider.GetLoggedResult(InternalCommand, null, originalResult, _stopwatch.ElapsedMilliseconds, DataRows);
                _profiler.ReaderExecuted(InternalCommand, context);
            }

            return(originalResult);
        }