Compartir a través de


DbSet<TEntity>.FindAsync Method

Definition

Overloads

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%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%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