Interface IQueryInterceptor
Observes the lifecycle of the commands a context executes. The events are raised by the context's execution axis, not by the command: a DbCommand is only the event payload and cannot log or profile itself.
public interface IQueryInterceptor
- Extension Methods
Remarks
Register implementations with DataContextBuilder.AddInterceptor (applies to every context the
builder creates) or DataContext.AddInterceptor (per context instance). Interceptors are
invoked in registration order and must be thread-safe, since a context may execute concurrently.
A command created for a cached query plan is reused across executions, so implementations must not
change CommandText.
Methods
CommandExecuted(CommandEventData, DbCommand, TimeSpan)
Called after the command has executed successfully.
void CommandExecuted(CommandEventData eventData, DbCommand command, TimeSpan elapsed)
Parameters
eventDataCommandEventDataMetadata about the command.
commandDbCommandThe command that executed.
elapsedTimeSpanThe time spent executing the command.
CommandExecuting(CommandEventData, DbCommand)
Called immediately before the command is executed.
void CommandExecuting(CommandEventData eventData, DbCommand command)
Parameters
eventDataCommandEventDataMetadata about the command.
commandDbCommandThe command about to execute.
CommandFailed(CommandEventData, DbCommand, Exception)
Called when executing the command throws.
void CommandFailed(CommandEventData eventData, DbCommand command, Exception exception)
Parameters
eventDataCommandEventDataMetadata about the command.
commandDbCommandThe command that failed.
exceptionExceptionThe exception thrown by the provider.
CommandInitialized(CommandEventData, DbCommand)
Called when a command has been created and its parameters bound. For a query it is raised once, by the planning axis, when the plan is built (a cache hit does not raise it again); for a DML statement it is raised on every execution, because mutation commands are not cached.
void CommandInitialized(CommandEventData eventData, DbCommand command)
Parameters
eventDataCommandEventDataMetadata about the command.
commandDbCommandThe command that was created.