ISaveChangesInterceptor Interface

Definition

Allows interception of the DbContext.SaveChanges and DbContext.SaveChangesAync methods.

Command interceptors can be used to view, change, or suppress execution of the SaveChanges call and modify the result before it is returned to EF.

Consider inheriting from SaveChangesInterceptor if not implementing all methods.

Use AddInterceptors(IInterceptor[]) to register application interceptors.

Extensions can also register interceptors in the internal service provider. If both injected and application interceptors are found, then the injected interceptors are run in the order that they are resolved from the service provider, and then the application interceptors are run last.

public interface ISaveChangesInterceptor : Microsoft.EntityFrameworkCore.Diagnostics.IInterceptor
type ISaveChangesInterceptor = interface
    interface IInterceptor
Public Interface ISaveChangesInterceptor
Implements IInterceptor
Derived
Implements

Methods

SaveChangesFailed(DbContextErrorEventData)

Called when an exception has been thrown in DbContext.SaveChanges.

SaveChangesFailedAsync(DbContextErrorEventData, CancellationToken)

Called when an exception has been thrown in DbContext.SaveChangesAsync.

SavedChanges(SaveChangesCompletedEventData, Int32)

Called at the end of DbContext.SaveChanges.

This method is still called if an interceptor suppressed creation of a command in SavingChanges(DbContextEventData, InterceptionResult<Int32>). In this case, result is the result returned by SavingChanges(DbContextEventData, InterceptionResult<Int32>).

SavedChangesAsync(SaveChangesCompletedEventData, Int32, CancellationToken)

Called at the end of DbContext.SaveChangesAsync.

This method is still called if an interceptor suppressed creation of a command in SavingChangesAsync(DbContextEventData, InterceptionResult<Int32>, CancellationToken). In this case, result is the result returned by SavingChangesAsync(DbContextEventData, InterceptionResult<Int32>, CancellationToken).

SavingChanges(DbContextEventData, InterceptionResult<Int32>)

Called at the start of DbContext.SaveChanges.

SavingChangesAsync(DbContextEventData, InterceptionResult<Int32>, CancellationToken)

Called at the start of DbContext.SaveChangesAsync.

Applies to