public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext <DbDataReader> interceptionContext) { _stopwatch.Stop(); DataTable dataTable = null; if (interceptionContext.OriginalException == null) { var dataSet = new DataSet { EnforceConstraints = false }; dataTable = new DataTable(tableName: Guid.NewGuid().ToString()); dataSet.Tables.Add(dataTable); dataSet.Load(interceptionContext.OriginalResult, LoadOption.OverwriteChanges, dataTable); interceptionContext.Result = dataTable.CreateDataReader(); } var context = EFProfilerContextProvider.GetLoggedResult(command, interceptionContext, _stopwatch.ElapsedMilliseconds, dataTable); _profiler.ReaderExecuted(command, context); }
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); }