Table of Contents

Interface IIdentityResolutionInterceptor

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

Allows interception of identity resolution conflicts when the DbContext starts tracking new entity instances.

public interface IIdentityResolutionInterceptor : IInterceptor

Remarks

A DbContext can only track one entity instance with any given primary key value. This means multiple instances of an entity with the same key value must be resolved to a single instance. An interceptor of this type can be used to do this. It is called with the existing tracked instance and the new instance and must apply any property values and relationship changes from the new instance into the existing instance. The new instance is then discarded.

Use AddInterceptors(params 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.

See EF Core interceptors and EF Core change tracking for more information and examples.

Methods

UpdateTrackedInstance(IdentityResolutionInterceptionData, EntityEntry, object)

Called when a DbContext attempts to track a new instance of an entity with the same primary key value as an already tracked instance. This method must apply any property values and relationship changes from the new instance into the existing instance. The new instance is then discarded.

void UpdateTrackedInstance(IdentityResolutionInterceptionData interceptionData, EntityEntry existingEntry, object newEntity)

Parameters

interceptionData IdentityResolutionInterceptionData

Contextual information about the identity resolution.

existingEntry EntityEntry

The entry for the existing tracked entity instance.

newEntity object

The new entity instance, which will be discarded after this call.