Table of Contents

Class DbContextExtensions

Namespace
JsonApiDotNetCore.Repositories
Assembly
JsonApiDotNetCore.dll
[PublicAPI]
public static class DbContextExtensions
Inheritance
DbContextExtensions
Inherited Members

Methods

GetTrackedIdentifiable(DbContext, IIdentifiable)

Searches the change tracker for an entity that matches the type and ID of identifiable.

public static object? GetTrackedIdentifiable(this DbContext dbContext, IIdentifiable identifiable)

Parameters

dbContext DbContext
identifiable IIdentifiable

Returns

object

GetTrackedOrAttach(DbContext, IIdentifiable)

If not already tracked, attaches the specified resource to the change tracker in Unchanged state.

public static IIdentifiable GetTrackedOrAttach(this DbContext dbContext, IIdentifiable resource)

Parameters

dbContext DbContext
resource IIdentifiable

Returns

IIdentifiable

Remarks

Repeated calls to this method in repository operations may appear redundant at first glance, but are intentional safeguards. User-defined resource definition callbacks execute external code that may query or attach entities into the change tracker. Calling this method ensures the repository always transitions from detached placeholders to the actively tracked instances managed by EF Core.

ResetChangeTracker(DbContext)

Detaches all entities from the change tracker.

public static void ResetChangeTracker(this DbContext dbContext)

Parameters

dbContext DbContext