Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

EntityFrameworkQueryableExtensions.AsNoTracking<TEntity> Method

Definition

Namespace:
Microsoft.EntityFrameworkCore
Assembly:
Microsoft.EntityFrameworkCore.dll
Package:
Microsoft.EntityFrameworkCore v1.0.6
Package:
Microsoft.EntityFrameworkCore v1.1.6
Package:
Microsoft.EntityFrameworkCore v10.0.0
Package:
Microsoft.EntityFrameworkCore v2.0.3
Package:
Microsoft.EntityFrameworkCore v2.1.11
Package:
Microsoft.EntityFrameworkCore v2.2.6
Package:
Microsoft.EntityFrameworkCore v3.0.0
Package:
Microsoft.EntityFrameworkCore v3.1.0
Package:
Microsoft.EntityFrameworkCore v5.0.0
Package:
Microsoft.EntityFrameworkCore v6.0.0
Package:
Microsoft.EntityFrameworkCore v7.0.0
Package:
Microsoft.EntityFrameworkCore v8.0.0
Package:
Microsoft.EntityFrameworkCore v9.0.0
Source:
EntityFrameworkQueryableExtensions.cs
Source:
EntityFrameworkQueryableExtensions.cs
Source:
EntityFrameworkQueryableExtensions.cs
Source:
EntityFrameworkQueryableExtensions.cs
Source:
EntityFrameworkQueryableExtensions.cs
Source:
EntityFrameworkQueryableExtensions.cs
Source:
EntityFrameworkQueryableExtensions.cs
Source:
EntityFrameworkQueryableExtensions.cs
Source:
EntityFrameworkQueryableExtensions.cs
Source:
EntityFrameworkQueryableExtensions.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

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


Feedback

Was this page helpful?