Note

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

Access to this page requires authorization. You can try .

DbSet<TEntity>.FindAsync Method

Definition

Namespace:
Microsoft.EntityFrameworkCore
Assembly:
Microsoft.EntityFrameworkCore.dll
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

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.

Overloads

Name Description
FindAsync(Object[])

Finds an entity with the given primary key values. If an entity with the given primary key values is being tracked by the context, then it is returned immediately without making a request to the database. Otherwise, a query is made to the database for an entity with the given primary key values and this entity, if found, is attached to the context and returned. If no entity is found, then null is returned.

FindAsync(Object[], CancellationToken)

Finds an entity with the given primary key values. If an entity with the given primary key values is being tracked by the context, then it is returned immediately without making a request to the database. Otherwise, a query is made to the database for an entity with the given primary key values and this entity, if found, is attached to the context and returned. If no entity is found, then null is returned.

FindAsync(Object[])

Source:
DbSet.cs
Source:
DbSet%60.cs
Source:
DbSet%60.cs
Source:
DbSet.cs
Source:
DbSet.cs
Source:
DbSet.cs
Source:
DbSet.cs
Source:
DbSet.cs
Source:
DbSet.cs
Source:
DbSet.cs

Finds an entity with the given primary key values. If an entity with the given primary key values is being tracked by the context, then it is returned immediately without making a request to the database. Otherwise, a query is made to the database for an entity with the given primary key values and this entity, if found, is attached to the context and returned. If no entity is found, then null is returned.

public virtual System.Threading.Tasks.Task<TEntity> FindAsync(params object[] keyValues);
public virtual System.Threading.Tasks.ValueTask<TEntity?> FindAsync(params object?[]? keyValues);
public virtual System.Threading.Tasks.ValueTask<TEntity> FindAsync(params object[] keyValues);
abstract member FindAsync : obj[] -> System.Threading.Tasks.Task<'Entity (requires 'Entity : null)>
override this.FindAsync : obj[] -> System.Threading.Tasks.Task<'Entity (requires 'Entity : null)>
abstract member FindAsync : obj[] -> System.Threading.Tasks.ValueTask<'Entity (requires 'Entity : null)>
override this.FindAsync : obj[] -> System.Threading.Tasks.ValueTask<'Entity (requires 'Entity : null)>
Public Overridable Function FindAsync (ParamArray keyValues As Object()) As Task(Of TEntity)
Public Overridable Function FindAsync (ParamArray keyValues As Object()) As ValueTask(Of TEntity)

Parameters

keyValues
Object[]

The values of the primary key for the entity to be found.

Returns

Task<TEntity>
ValueTask<TEntity>

The entity found, or null.

Remarks

See Using Find and FindAsync for more information and examples.

Applies to

FindAsync(Object[], CancellationToken)

Source:
DbSet.cs
Source:
DbSet%60.cs
Source:
DbSet%60.cs
Source:
DbSet.cs
Source:
DbSet.cs
Source:
DbSet.cs
Source:
DbSet.cs
Source:
DbSet.cs
Source:
DbSet.cs
Source:
DbSet.cs

Finds an entity with the given primary key values. If an entity with the given primary key values is being tracked by the context, then it is returned immediately without making a request to the database. Otherwise, a query is made to the database for an entity with the given primary key values and this entity, if found, is attached to the context and returned. If no entity is found, then null is returned.

public virtual System.Threading.Tasks.Task<TEntity> FindAsync(object[] keyValues, System.Threading.CancellationToken cancellationToken);
public virtual System.Threading.Tasks.ValueTask<TEntity?> FindAsync(object?[]? keyValues, System.Threading.CancellationToken cancellationToken);
public virtual System.Threading.Tasks.ValueTask<TEntity> FindAsync(object[] keyValues, System.Threading.CancellationToken cancellationToken);
abstract member FindAsync : obj[] * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Entity (requires 'Entity : null)>
override this.FindAsync : obj[] * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Entity (requires 'Entity : null)>
abstract member FindAsync : obj[] * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Entity (requires 'Entity : null)>
override this.FindAsync : obj[] * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<'Entity (requires 'Entity : null)>
Public Overridable Function FindAsync (keyValues As Object(), cancellationToken As CancellationToken) As Task(Of TEntity)
Public Overridable Function FindAsync (keyValues As Object(), cancellationToken As CancellationToken) As ValueTask(Of TEntity)

Parameters

keyValues
Object[]

The values of the primary key for the entity to be found.

cancellationToken
CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task<TEntity>
ValueTask<TEntity>

The entity found, or null.

Exceptions

Remarks

See Using Find and FindAsync for more information and examples.

Applies to


Feedback

Was this page helpful?