DbContextOptionsBuilder.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 UseQueryTrackingBehavior (Microsoft.EntityFrameworkCore.QueryTrackingBehavior queryTrackingBehavior);
abstract member UseQueryTrackingBehavior : Microsoft.EntityFrameworkCore.QueryTrackingBehavior -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
override this.UseQueryTrackingBehavior : Microsoft.EntityFrameworkCore.QueryTrackingBehavior -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
Public Overridable Function UseQueryTrackingBehavior (queryTrackingBehavior As QueryTrackingBehavior) As DbContextOptionsBuilder

Parameters

queryTrackingBehavior
QueryTrackingBehavior

Returns

The same builder instance so that multiple calls can be chained.

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