Table of Contents

Class DbConnectionInterceptor

Namespace
Microsoft.EntityFrameworkCore.Diagnostics
Assembly
Microsoft.EntityFrameworkCore.Relational.dll

Abstract base class for IDbConnectionInterceptor for use when implementing a subset of the interface methods.

public abstract class DbConnectionInterceptor : IDbConnectionInterceptor, IInterceptor
Inheritance
DbConnectionInterceptor
Implements
IInterceptor
Inherited Members

Constructors

DbConnectionInterceptor()

protected DbConnectionInterceptor()

Methods

ConnectionClosed(DbConnection, ConnectionEndEventData)

Called just after EF has called Close() in an async context.

public virtual void ConnectionClosed(DbConnection connection, ConnectionEndEventData eventData)

Parameters

connection DbConnection

The connection.

eventData ConnectionEndEventData

Contextual information about the connection.

ConnectionClosedAsync(DbConnection, ConnectionEndEventData)

Called just after EF has called CloseAsync().

public virtual Task ConnectionClosedAsync(DbConnection connection, ConnectionEndEventData eventData)

Parameters

connection DbConnection

The connection.

eventData ConnectionEndEventData

Contextual information about the connection.

Returns

Task

A Task representing the asynchronous operation.

ConnectionClosing(DbConnection, ConnectionEventData, InterceptionResult)

Called just before EF intends to call Close().

public virtual InterceptionResult ConnectionClosing(DbConnection connection, ConnectionEventData eventData, InterceptionResult result)

Parameters

connection DbConnection

The connection.

eventData ConnectionEventData

Contextual information about the connection.

result InterceptionResult

Represents 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.

ConnectionClosingAsync(DbConnection, ConnectionEventData, InterceptionResult)

Called just before EF intends to call CloseAsync() in an async context.

public virtual ValueTask<InterceptionResult> ConnectionClosingAsync(DbConnection connection, ConnectionEventData eventData, InterceptionResult result)

Parameters

connection DbConnection

The connection.

eventData ConnectionEventData

Contextual information about the connection.

result InterceptionResult

Represents 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

ValueTask<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.

ConnectionFailed(DbConnection, ConnectionErrorEventData)

Called when opening of a connection has failed with an exception.

public virtual void ConnectionFailed(DbConnection connection, ConnectionErrorEventData eventData)

Parameters

connection DbConnection

The connection.

eventData ConnectionErrorEventData

Contextual information about the connection.

ConnectionFailedAsync(DbConnection, ConnectionErrorEventData, CancellationToken)

Called when opening of a connection has failed with an exception.

public virtual Task ConnectionFailedAsync(DbConnection connection, ConnectionErrorEventData eventData, CancellationToken cancellationToken = default)

Parameters

connection DbConnection

The connection.

eventData ConnectionErrorEventData

Contextual information about the connection.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A Task representing the asynchronous operation.

ConnectionOpened(DbConnection, ConnectionEndEventData)

Called just after EF has called Open().

public virtual void ConnectionOpened(DbConnection connection, ConnectionEndEventData eventData)

Parameters

connection DbConnection

The connection.

eventData ConnectionEndEventData

Contextual information about the connection.

ConnectionOpenedAsync(DbConnection, ConnectionEndEventData, CancellationToken)

Called just after EF has called OpenAsync().

public virtual Task ConnectionOpenedAsync(DbConnection connection, ConnectionEndEventData eventData, CancellationToken cancellationToken = default)

Parameters

connection DbConnection

The connection.

eventData ConnectionEndEventData

Contextual information about the connection.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A Task representing the asynchronous operation.

ConnectionOpening(DbConnection, ConnectionEventData, InterceptionResult)

Called just before EF intends to call Open().

public virtual InterceptionResult ConnectionOpening(DbConnection connection, ConnectionEventData eventData, InterceptionResult result)

Parameters

connection DbConnection

The connection.

eventData ConnectionEventData

Contextual information about the connection.

result InterceptionResult

Represents 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.

ConnectionOpeningAsync(DbConnection, ConnectionEventData, InterceptionResult, CancellationToken)

Called just before EF intends to call OpenAsync().

public virtual ValueTask<InterceptionResult> ConnectionOpeningAsync(DbConnection connection, ConnectionEventData eventData, InterceptionResult result, CancellationToken cancellationToken = default)

Parameters

connection DbConnection

The connection.

eventData ConnectionEventData

Contextual information about the connection.

result InterceptionResult

Represents 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.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask<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.