共用方式為


EntityFrameworkQueryableExtensions.AsTracking Method

Definition

Overloads

AsTracking<TEntity>(IQueryable<TEntity>)

Returns a new query where the change tracker will keep track of changes for all entities that are returned. Any modification to the entity instances will be detected and persisted to the database during SaveChanges().

AsTracking<TEntity>(IQueryable<TEntity>, QueryTrackingBehavior)

Returns a new query where the change tracker will either keep track of changes or not for all entities that are returned, depending on the value of the 'track' parameter. When tracking, Any modification to the entity instances will be detected and persisted to the database during SaveChanges(). When not tracking, 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.

AsTracking<TEntity>(IQueryable<TEntity>)

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

Returns a new query where the change tracker will keep track of changes for all entities that are returned. Any modification to the entity instances will be detected and persisted to the database during SaveChanges().

public static System.Linq.IQueryable<TEntity> AsTracking<TEntity> (this System.Linq.IQueryable<TEntity> source) where TEntity : class;
static member AsTracking : System.Linq.IQueryable<'Entity (requires 'Entity : null)> -> System.Linq.IQueryable<'Entity (requires 'Entity : null)> (requires 'Entity : null)
<Extension()>
Public Function AsTracking(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 be tracked by the context.

Exceptions

source is null.

Remarks

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

See Tracking queries in EF Core for more information and examples.

Applies to

AsTracking<TEntity>(IQueryable<TEntity>, QueryTrackingBehavior)

Source:
EntityFrameworkQueryableExtensions.cs
Source:
EntityFrameworkQueryableExtensions.cs
Source:
EntityFrameworkQueryableExtensions.cs
Source:
EntityFrameworkQueryableExtensions.cs
Source:
EntityFrameworkQueryableExtensions.cs
Source:
EntityFrameworkQueryableExtensions.cs
Source:
EntityFrameworkQueryableExtensions.cs

Returns a new query where the change tracker will either keep track of changes or not for all entities that are returned, depending on the value of the 'track' parameter. When tracking, Any modification to the entity instances will be detected and persisted to the database during SaveChanges(). When not tracking, 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> AsTracking<TEntity> (this System.Linq.IQueryable<TEntity> source, Microsoft.EntityFrameworkCore.QueryTrackingBehavior track) where TEntity : class;
static member AsTracking : System.Linq.IQueryable<'Entity (requires 'Entity : null)> * Microsoft.EntityFrameworkCore.QueryTrackingBehavior -> System.Linq.IQueryable<'Entity (requires 'Entity : null)> (requires 'Entity : null)
<Extension()>
Public Function AsTracking(Of TEntity As Class) (source As IQueryable(Of TEntity), track As QueryTrackingBehavior) As IQueryable(Of TEntity)

Type Parameters

TEntity

The type of entity being queried.

Parameters

source
IQueryable<TEntity>

The source query.

track
QueryTrackingBehavior

Indicates whether the query will track results or not.

Returns

IQueryable<TEntity>

A new query where the result set will 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().

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

See Tracking queries in EF Core for more information and examples.

Applies to