internal void RaiseFinished(CommandExecutionEventArgs e) { if (CommandFinished != null) { CommandFinished(this, e); } }
/// <summary> /// Executes the query and returns the first column of the first row in the result set /// returned by the query. All other columns and rows are ignored. /// </summary> /// <returns> /// The first column of the first row in the result set. /// </returns> public override object ExecuteScalar() { var e = new CommandExecutionEventArgs(this, "ExecuteScalar") { Status = CommandExecutionStatus.Executing }; Connection.RaiseExecuting(e); var sw = new Stopwatch(); try { sw.Start(); var result = base.ExecuteScalar(); sw.Stop(); e.Result = result; e.Duration = sw.Elapsed; e.Status = CommandExecutionStatus.Finished; Connection.RaiseFinished(e); return result; } catch (Exception ex) { e.Result = ex; e.Status = CommandExecutionStatus.Failed; Connection.RaiseFailed(e); throw; } }
internal void RaiseExecuting(CommandExecutionEventArgs e) { if (CommandExecuting != null) { CommandExecuting(this, e); } }
/// <summary> /// Executes the command text against the connection. /// </summary> /// <param name="behavior">An instance of <see cref="T:System.Data.CommandBehavior"/>.</param> /// <returns> /// A <see cref="T:System.Data.Common.DbDataReader"/>. /// </returns> protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { var e = new CommandExecutionEventArgs(this, "ExecuteReader") { Status = CommandExecutionStatus.Executing }; Connection.RaiseExecuting(e); try { var sw = new Stopwatch(); sw.Start(); var result = base.ExecuteDbDataReader(behavior); sw.Stop(); e.Result = result; e.Status = CommandExecutionStatus.Finished; e.Duration = sw.Elapsed; Connection.RaiseFinished(e); return result; } catch (Exception ex) { e.Result = ex; e.Status = CommandExecutionStatus.Failed; Connection.RaiseFailed(e); throw; } }