public IDataReader ExecuteReader(string cmdText, DbParam[] parameters, CommandType cmdType, CommandBehavior behavior) { this.CheckDisposed(); List <OutputParameter> outputParameters; IDbCommand cmd = this.PrepareCommand(cmdText, parameters, cmdType, out outputParameters); DbCommandInterceptionContext <IDataReader> dbCommandInterceptionContext = new DbCommandInterceptionContext <IDataReader>(); IDbCommandInterceptor[] globalInterceptors = DbInterception.GetInterceptors(); this.Activate(); this.OnReaderExecuting(cmd, dbCommandInterceptionContext, globalInterceptors); IDataReader reader; try { reader = new InternalDataReader(this, cmd.ExecuteReader(behavior), cmd, outputParameters); } catch (Exception ex) { dbCommandInterceptionContext.Exception = ex; this.OnReaderExecuted(cmd, dbCommandInterceptionContext, globalInterceptors); throw WrapException(ex); } dbCommandInterceptionContext.Result = reader; this.OnReaderExecuted(cmd, dbCommandInterceptionContext, globalInterceptors); return(reader); }
public object ExecuteScalar(string cmdText, DbParam[] parameters, CommandType cmdType) { this.CheckDisposed(); IDbCommand cmd = null; try { List <OutputParameter> outputParameters; cmd = this.PrepareCommand(cmdText, parameters, cmdType, out outputParameters); DbCommandInterceptionContext <object> dbCommandInterceptionContext = new DbCommandInterceptionContext <object>(); IDbCommandInterceptor[] globalInterceptors = DbInterception.GetInterceptors(); this.Activate(); this.OnScalarExecuting(cmd, dbCommandInterceptionContext, globalInterceptors); object ret; try { ret = cmd.ExecuteScalar(); } catch (Exception ex) { dbCommandInterceptionContext.Exception = ex; this.OnScalarExecuted(cmd, dbCommandInterceptionContext, globalInterceptors); throw WrapException(ex); } dbCommandInterceptionContext.Result = ret; this.OnScalarExecuted(cmd, dbCommandInterceptionContext, globalInterceptors); OutputParameter.CallMapValue(outputParameters); return(ret); } finally { this.Complete(); if (cmd != null) { cmd.Dispose(); } } }