Class DbCommandInterceptor
- Namespace
- Microsoft.EntityFrameworkCore.Diagnostics
- Assembly
- Microsoft.EntityFrameworkCore.Relational.dll
Abstract base class for IDbCommandInterceptor for use when implementing a subset of the interface methods.
public abstract class DbCommandInterceptor : IDbCommandInterceptor, IInterceptor
- Inheritance
-
DbCommandInterceptor
- Implements
-
IInterceptor
- Inherited Members
Constructors
DbCommandInterceptor()
protected DbCommandInterceptor()
Methods
CommandCreated(CommandEndEventData, DbCommand)
Called immediately after EF calls CreateCommand().
This method is still called if an interceptor suppressed creation of a command in
CommandCreating(CommandCorrelatedEventData, InterceptionResult<DbCommand>).
In this case, result
is the result returned by CommandCreating(CommandCorrelatedEventData, InterceptionResult<DbCommand>).
public virtual DbCommand CommandCreated(CommandEndEventData eventData, DbCommand result)
Parameters
eventData
CommandEndEventDataContextual information about the command and execution.
result
DbCommandThe result of the call to CreateCommand(). This value is typically used as the return value for the implementation of this method.
Returns
- DbCommand
The result that EF will use. A normal implementation of this method for any interceptor that is not attempting to change the result is to return the
result
value passed in.
CommandCreating(CommandCorrelatedEventData, InterceptionResult<DbCommand>)
Called just before EF intends to call CreateCommand().
public virtual InterceptionResult<DbCommand> CommandCreating(CommandCorrelatedEventData eventData, InterceptionResult<DbCommand> result)
Parameters
eventData
CommandCorrelatedEventDataContextual information about the command and execution.
result
InterceptionResult<DbCommand>Represents the current result if one exists. This value will have Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult set to true if some previous interceptor suppressed execution by calling Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.SuppressWithResult(`0). This value is typically used as the return value for the implementation of this method.
Returns
- InterceptionResult<DbCommand>
If Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult is false, the EF will continue as normal. If Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult is true, then EF will suppress the operation it was about to perform and use Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.Result instead. A normal implementation of this method for any interceptor that is not attempting to change the result is to return the
result
value passed in.
CommandFailed(DbCommand, CommandErrorEventData)
Called when execution of a command has failed with an exception.
public virtual void CommandFailed(DbCommand command, CommandErrorEventData eventData)
Parameters
command
DbCommandThe command.
eventData
CommandErrorEventDataContextual information about the command and execution.
CommandFailedAsync(DbCommand, CommandErrorEventData, CancellationToken)
Called when execution of a command has failed with an exception.
public virtual Task CommandFailedAsync(DbCommand command, CommandErrorEventData eventData, CancellationToken cancellationToken = default)
Parameters
command
DbCommandThe command.
eventData
CommandErrorEventDataContextual information about the command and execution.
cancellationToken
CancellationTokenThe cancellation token.
Returns
DataReaderDisposing(DbCommand, DataReaderDisposingEventData, InterceptionResult)
Called when execution of a DbDataReader is about to be disposed.
public virtual InterceptionResult DataReaderDisposing(DbCommand command, DataReaderDisposingEventData eventData, InterceptionResult result)
Parameters
command
DbCommandThe command.
eventData
DataReaderDisposingEventDataContextual information about the command and reader.
result
InterceptionResultRepresents the current result if one exists. This value will have Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult.IsSuppressed set to true if some previous interceptor suppressed execution by calling Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult.Suppress. This value is typically used as the return value for the implementation of this method.
Returns
- InterceptionResult
If Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult.IsSuppressed is false, the EF will continue as normal. If Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult.IsSuppressed is true, then EF will suppress the operation it was about to perform. A normal implementation of this method for any interceptor that is not attempting to suppress the operation is to return the
result
value passed in.
NonQueryExecuted(DbCommand, CommandExecutedEventData, int)
Called immediately after EF calls ExecuteNonQuery().
This method is still called if an interceptor suppressed execution of a command in NonQueryExecuting(DbCommand, CommandEventData, InterceptionResult<int>).
In this case, result
is the result returned by NonQueryExecuting(DbCommand, CommandEventData, InterceptionResult<int>).
public virtual int NonQueryExecuted(DbCommand command, CommandExecutedEventData eventData, int result)
Parameters
command
DbCommandThe command.
eventData
CommandExecutedEventDataContextual information about the command and execution.
result
intThe result of the call to ExecuteNonQuery(). This value is typically used as the return value for the implementation of this method.
Returns
- int
The result that EF will use. A normal implementation of this method for any interceptor that is not attempting to change the result is to return the
result
value passed in.
NonQueryExecutedAsync(DbCommand, CommandExecutedEventData, int, CancellationToken)
Called immediately after EF calls ExecuteNonQueryAsync().
This method is still called if an interceptor suppressed execution of a command in NonQueryExecutingAsync(DbCommand, CommandEventData, InterceptionResult<int>, CancellationToken).
In this case, result
is the result returned by NonQueryExecutingAsync(DbCommand, CommandEventData, InterceptionResult<int>, CancellationToken).
public virtual ValueTask<int> NonQueryExecutedAsync(DbCommand command, CommandExecutedEventData eventData, int result, CancellationToken cancellationToken = default)
Parameters
command
DbCommandThe command.
eventData
CommandExecutedEventDataContextual information about the command and execution.
result
intThe result of the call to ExecuteNonQueryAsync(). This value is typically used as the return value for the implementation of this method.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- ValueTask<int>
A Task providing the result that EF will use. A normal implementation of this method for any interceptor that is not attempting to change the result is to return the
result
value passed in, often using FromResult<TResult>(TResult)
NonQueryExecuting(DbCommand, CommandEventData, InterceptionResult<int>)
Called just before EF intends to call ExecuteNonQuery().
public virtual InterceptionResult<int> NonQueryExecuting(DbCommand command, CommandEventData eventData, InterceptionResult<int> result)
Parameters
command
DbCommandThe command.
eventData
CommandEventDataContextual information about the command and execution.
result
InterceptionResult<int>Represents the current result if one exists. This value will have Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult set to true if some previous interceptor suppressed execution by calling Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.SuppressWithResult(`0). This value is typically used as the return value for the implementation of this method.
Returns
- InterceptionResult<int>
If Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult is false, the EF will continue as normal. If Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult is true, then EF will suppress the operation it was about to perform and use Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.Result instead. A normal implementation of this method for any interceptor that is not attempting to change the result is to return the
result
value passed in, often using FromResult<TResult>(TResult)
NonQueryExecutingAsync(DbCommand, CommandEventData, InterceptionResult<int>, CancellationToken)
Called just before EF intends to call ExecuteNonQueryAsync().
public virtual ValueTask<InterceptionResult<int>> NonQueryExecutingAsync(DbCommand command, CommandEventData eventData, InterceptionResult<int> result, CancellationToken cancellationToken = default)
Parameters
command
DbCommandThe command.
eventData
CommandEventDataContextual information about the command and execution.
result
InterceptionResult<int>Represents the current result if one exists. This value will have Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult set to true if some previous interceptor suppressed execution by calling Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.SuppressWithResult(`0). This value is typically used as the return value for the implementation of this method.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- ValueTask<InterceptionResult<int>>
If Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult is false, the EF will continue as normal. If Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult is true, then EF will suppress the operation it was about to perform and use Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.Result instead. A normal implementation of this method for any interceptor that is not attempting to change the result is to return the
result
value passed in, often using FromResult<TResult>(TResult)
ReaderExecuted(DbCommand, CommandExecutedEventData, DbDataReader)
Called immediately after EF calls ExecuteReader().
This method is still called if an interceptor suppressed execution of a command in ReaderExecuting(DbCommand, CommandEventData, InterceptionResult<DbDataReader>).
In this case, result
is the result returned by ReaderExecuting(DbCommand, CommandEventData, InterceptionResult<DbDataReader>).
public virtual DbDataReader ReaderExecuted(DbCommand command, CommandExecutedEventData eventData, DbDataReader result)
Parameters
command
DbCommandThe command.
eventData
CommandExecutedEventDataContextual information about the command and execution.
result
DbDataReaderThe result of the call to ExecuteReader(). This value is typically used as the return value for the implementation of this method.
Returns
- DbDataReader
The result that EF will use. A normal implementation of this method for any interceptor that is not attempting to change the result is to return the
result
value passed in.
ReaderExecutedAsync(DbCommand, CommandExecutedEventData, DbDataReader, CancellationToken)
Called immediately after EF calls ExecuteReaderAsync().
This method is still called if an interceptor suppressed execution of a command in ReaderExecutingAsync(DbCommand, CommandEventData, InterceptionResult<DbDataReader>, CancellationToken).
In this case, result
is the result returned by ReaderExecutingAsync(DbCommand, CommandEventData, InterceptionResult<DbDataReader>, CancellationToken).
public virtual ValueTask<DbDataReader> ReaderExecutedAsync(DbCommand command, CommandExecutedEventData eventData, DbDataReader result, CancellationToken cancellationToken = default)
Parameters
command
DbCommandThe command.
eventData
CommandExecutedEventDataContextual information about the command and execution.
result
DbDataReaderThe result of the call to ExecuteReaderAsync(). This value is typically used as the return value for the implementation of this method.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- ValueTask<DbDataReader>
A Task providing the result that EF will use. A normal implementation of this method for any interceptor that is not attempting to change the result is to return the
result
value passed in, often using FromResult<TResult>(TResult)
ReaderExecuting(DbCommand, CommandEventData, InterceptionResult<DbDataReader>)
Called just before EF intends to call ExecuteReader().
public virtual InterceptionResult<DbDataReader> ReaderExecuting(DbCommand command, CommandEventData eventData, InterceptionResult<DbDataReader> result)
Parameters
command
DbCommandThe command.
eventData
CommandEventDataContextual information about the command and execution.
result
InterceptionResult<DbDataReader>Represents the current result if one exists. This value will have Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult set to true if some previous interceptor suppressed execution by calling Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.SuppressWithResult(`0). This value is typically used as the return value for the implementation of this method.
Returns
- InterceptionResult<DbDataReader>
If Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult is false, the EF will continue as normal. If Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult is true, then EF will suppress the operation it was about to perform and use Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.Result instead. A normal implementation of this method for any interceptor that is not attempting to change the result is to return the
result
value passed in, often using FromResult<TResult>(TResult)
ReaderExecutingAsync(DbCommand, CommandEventData, InterceptionResult<DbDataReader>, CancellationToken)
Called just before EF intends to call ExecuteReaderAsync().
public virtual ValueTask<InterceptionResult<DbDataReader>> ReaderExecutingAsync(DbCommand command, CommandEventData eventData, InterceptionResult<DbDataReader> result, CancellationToken cancellationToken = default)
Parameters
command
DbCommandThe command.
eventData
CommandEventDataContextual information about the command and execution.
result
InterceptionResult<DbDataReader>Represents the current result if one exists. This value will have Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult set to true if some previous interceptor suppressed execution by calling Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.SuppressWithResult(`0). This value is typically used as the return value for the implementation of this method.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- ValueTask<InterceptionResult<DbDataReader>>
If Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult is false, the EF will continue as normal. If Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult is true, then EF will suppress the operation it was about to perform and use Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.Result instead. A normal implementation of this method for any interceptor that is not attempting to change the result is to return the
result
value passed in, often using FromResult<TResult>(TResult)
ScalarExecuted(DbCommand, CommandExecutedEventData, object)
Called immediately after EF calls ExecuteScalar().
This method is still called if an interceptor suppressed execution of a command in ScalarExecuting(DbCommand, CommandEventData, InterceptionResult<object>).
In this case, result
is the result returned by ScalarExecuting(DbCommand, CommandEventData, InterceptionResult<object>).
public virtual object ScalarExecuted(DbCommand command, CommandExecutedEventData eventData, object result)
Parameters
command
DbCommandThe command.
eventData
CommandExecutedEventDataContextual information about the command and execution.
result
objectThe result of the call to ExecuteScalar(). This value is typically used as the return value for the implementation of this method.
Returns
- object
The result that EF will use. A normal implementation of this method for any interceptor that is not attempting to change the result is to return the
result
value passed in.
ScalarExecutedAsync(DbCommand, CommandExecutedEventData, object, CancellationToken)
Called immediately after EF calls ExecuteScalarAsync().
This method is still called if an interceptor suppressed execution of a command in ScalarExecutingAsync(DbCommand, CommandEventData, InterceptionResult<object>, CancellationToken).
In this case, result
is the result returned by ScalarExecutingAsync(DbCommand, CommandEventData, InterceptionResult<object>, CancellationToken).
public virtual ValueTask<object> ScalarExecutedAsync(DbCommand command, CommandExecutedEventData eventData, object result, CancellationToken cancellationToken = default)
Parameters
command
DbCommandThe command.
eventData
CommandExecutedEventDataContextual information about the command and execution.
result
objectThe result of the call to ExecuteScalarAsync(). This value is typically used as the return value for the implementation of this method.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- ValueTask<object>
A Task providing the result that EF will use. A normal implementation of this method for any interceptor that is not attempting to change the result is to return the
result
value passed in, often using FromResult<TResult>(TResult)
ScalarExecuting(DbCommand, CommandEventData, InterceptionResult<object>)
Called just before EF intends to call ExecuteScalar().
public virtual InterceptionResult<object> ScalarExecuting(DbCommand command, CommandEventData eventData, InterceptionResult<object> result)
Parameters
command
DbCommandThe command.
eventData
CommandEventDataContextual information about the command and execution.
result
InterceptionResult<object>Represents the current result if one exists. This value will have Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult set to true if some previous interceptor suppressed execution by calling Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.SuppressWithResult(`0). This value is typically used as the return value for the implementation of this method.
Returns
- InterceptionResult<object>
If Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult is false, the EF will continue as normal. If Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult is true, then EF will suppress the operation it was about to perform and use Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.Result instead. A normal implementation of this method for any interceptor that is not attempting to change the result is to return the
result
value passed in, often using FromResult<TResult>(TResult)
ScalarExecutingAsync(DbCommand, CommandEventData, InterceptionResult<object>, CancellationToken)
Called just before EF intends to call ExecuteScalarAsync().
public virtual ValueTask<InterceptionResult<object>> ScalarExecutingAsync(DbCommand command, CommandEventData eventData, InterceptionResult<object> result, CancellationToken cancellationToken = default)
Parameters
command
DbCommandThe command.
eventData
CommandEventDataContextual information about the command and execution.
result
InterceptionResult<object>Represents the current result if one exists. This value will have Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult set to true if some previous interceptor suppressed execution by calling Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.SuppressWithResult(`0). This value is typically used as the return value for the implementation of this method.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- ValueTask<InterceptionResult<object>>
If Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult is false, the EF will continue as normal. If Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.HasResult is true, then EF will suppress the operation it was about to perform and use Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult`1.Result instead. A normal implementation of this method for any interceptor that is not attempting to change the result is to return the
result
value passed in, often using FromResult<TResult>(TResult)