语言

ISaveChangesInterceptor 接口

定义

允许截获 DbContext.SaveChanges 和 DbContext.SaveChangesAync 方法。

public interface ISaveChangesInterceptor : Microsoft.EntityFrameworkCore.Diagnostics.IInterceptor
type ISaveChangesInterceptor = interface
    interface IInterceptor
Public Interface ISaveChangesInterceptor
Implements IInterceptor
派生
实现

注解

SaveChanges 拦截器可用于查看、更改或禁止执行 SaveChanges 调用,并在结果返回到 EF 之前修改结果。

如果不是实现所有方法,请考虑从继承 SaveChangesInterceptor 。

用于 AddInterceptors(IInterceptor[]) 注册应用程序拦截器。

扩展还可以在内部服务提供商中注册侦听器。 如果同时找到注入的侦听器和应用程序拦截器,则注入的侦听器按从服务提供商解析的顺序运行,然后最后运行应用程序拦截器。

有关详细信息和示例,请参阅 EF Core 拦截器 。

方法

名称 说明
SaveChangesCanceled(DbContextEventData)

取消时 DbContext.SaveChanges 调用。

SaveChangesCanceledAsync(DbContextEventData, CancellationToken)

取消时 DbContext.SaveChangesAsync 调用。

SaveChangesFailed(DbContextErrorEventData)

在引发 DbContext.SaveChanges异常时调用。

SaveChangesFailedAsync(DbContextErrorEventData, CancellationToken)

在引发 DbContext.SaveChangesAsync异常时调用。

SavedChanges(SaveChangesCompletedEventData, Int32)

在结尾 DbContext.SaveChanges处调用 。

SavedChangesAsync(SaveChangesCompletedEventData, Int32, CancellationToken)

在结尾 DbContext.SaveChangesAsync处调用 。

SavingChanges(DbContextEventData, InterceptionResult<Int32>)

在开头 DbContext.SaveChanges调用 。

SavingChangesAsync(DbContextEventData, InterceptionResult<Int32>, CancellationToken)

在开头 DbContext.SaveChangesAsync调用 。

ThrowingConcurrencyException(ConcurrencyExceptionEventData, InterceptionResult)

在 EF 要引发之前 DbUpdateConcurrencyException立即调用 。

ThrowingConcurrencyExceptionAsync(ConcurrencyExceptionEventData, InterceptionResult, CancellationToken)

在 EF 要引发之前 DbUpdateConcurrencyException立即调用 。

适用于