Share via


DbContextOptionsBuilder<TContext>.UseQueryTrackingBehavior Method

Definition

Sets the tracking behavior for LINQ queries run against the context. Disabling change tracking is useful for read-only scenarios because it avoids the overhead of setting up change tracking for each entity instance. You should not disable change tracking if you want to manipulate entity instances and persist those changes to the database using SaveChanges().

public virtual Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<TContext> UseQueryTrackingBehavior (Microsoft.EntityFrameworkCore.QueryTrackingBehavior queryTrackingBehavior);
override this.UseQueryTrackingBehavior : Microsoft.EntityFrameworkCore.QueryTrackingBehavior -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<'Context (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)>
Public Overridable Function UseQueryTrackingBehavior (queryTrackingBehavior As QueryTrackingBehavior) As DbContextOptionsBuilder(Of TContext)

Parameters

queryTrackingBehavior
QueryTrackingBehavior

Returns

Remarks

This method sets the default behavior for all contexts created with these options, but you can override this behavior for a context instance using QueryTrackingBehavior or on individual queries using the AsNoTracking<TEntity>(IQueryable<TEntity>) and AsTracking<TEntity>(IQueryable<TEntity>) methods.

The default value is TrackAll. This means the change tracker will keep track of changes for all entities that are returned from a LINQ query.

See Using DbContextOptions and Querying data with EF Core for more information and examples.

Applies to