Table of Contents

Interface IMaterializationInterceptor

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

A ISingletonInterceptor used to intercept the various parts of object creation and initialization when Entity Framework is creating an object, typically from data returned by a query.

public interface IMaterializationInterceptor : ISingletonInterceptor, IInterceptor

Remarks

See EF Core interceptors for more information and examples.

Methods

CreatedInstance(MaterializationInterceptionData, object)

Called immediately after EF has created an instance of an entity. That is, after the constructor has been called, but before any properties values not set by the constructor have been set.

object CreatedInstance(MaterializationInterceptionData materializationData, object entity)

Parameters

materializationData MaterializationInterceptionData

Contextual information about the materialization happening.

entity object

The entity instance that has been created. This value is typically used as the return value for the implementation of this method.

Returns

object

The entity instance that EF will use. An implementation of this method for any interceptor that is not attempting to change the instance used must return the entity value passed in.

CreatingInstance(MaterializationInterceptionData, InterceptionResult<object>)

Called immediately before EF is going to create an instance of an entity. That is, before the constructor has been called.

InterceptionResult<object> CreatingInstance(MaterializationInterceptionData materializationData, InterceptionResult<object> result)

Parameters

materializationData MaterializationInterceptionData

Contextual information about the materialization happening.

result InterceptionResult<object>

Represents the current result if one exists. This value will have HasResult set to true if some previous interceptor suppressed execution by calling SuppressWithResult(TResult). This value is typically used as the return value for the implementation of this method.

Returns

InterceptionResult<object>

If HasResult is false, then EF will continue as normal. If HasResult is true, then EF will suppress creation of the entity instance and use Result instead. An implementation of this method for any interceptor that is not attempting to change the result should return the result value passed in.

InitializedInstance(MaterializationInterceptionData, object)

Called immediately after EF has set property values of an entity that has just been created.

object InitializedInstance(MaterializationInterceptionData materializationData, object entity)

Parameters

materializationData MaterializationInterceptionData

Contextual information about the materialization happening.

entity object

The entity instance that has been created. This value is typically used as the return value for the implementation of this method.

Returns

object

The entity instance that EF will use. An implementation of this method for any interceptor that is not attempting to change the instance used must return the entity value passed in.

InitializingInstance(MaterializationInterceptionData, object, InterceptionResult)

Called immediately before EF is going to set property values of an entity that has just been created. Note that property values set by the constructor will already have been set.

InterceptionResult InitializingInstance(MaterializationInterceptionData materializationData, object entity, InterceptionResult result)

Parameters

materializationData MaterializationInterceptionData

Contextual information about the materialization happening.

entity object

The entity instance for which property values will be set.

result InterceptionResult

Represents the current result if one exists. This value will have IsSuppressed set to true if some previous interceptor suppressed execution by calling Suppress(). This value is typically used as the return value for the implementation of this method.

Returns

InterceptionResult

If IsSuppressed is false, then EF will continue as normal. If IsSuppressed is true, then EF will not set any property values. An implementation of this method for any interceptor that is not attempting to suppress setting property values must return the result value passed in.