EntityFrameworkQueryableExtensions.AsNoTracking<TEntity> Method

Definition

The change tracker will not track any of the entities that are returned from a LINQ query. If the entity instances are modified, this will not be detected by the change tracker and SaveChanges() will not persist those changes to the database.

public static System.Linq.IQueryable<TEntity> AsNoTracking<TEntity> (this System.Linq.IQueryable<TEntity> source) where TEntity : class;
static member AsNoTracking : System.Linq.IQueryable<'Entity (requires 'Entity : null)> -> System.Linq.IQueryable<'Entity (requires 'Entity : null)> (requires 'Entity : null)
<Extension()>
Public Function AsNoTracking(Of TEntity As Class) (source As IQueryable(Of TEntity)) As IQueryable(Of TEntity)

Type Parameters

TEntity

The type of entity being queried.

Parameters

source
IQueryable<TEntity>

The source query.

Returns

IQueryable<TEntity>

A new query where the result set will not be tracked by the context.

Exceptions

source is null.

Remarks

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().

Identity resolution will not be performed. If an entity with a given key is in different result in the result set then they will be different instances.

The default tracking behavior for queries can be controlled by QueryTrackingBehavior.

See No-tracking queries in EF Core for more information and examples.

Applies to