Share via


DbSet<TEntity>.FindAsync Method

Definition

Overloads

FindAsync(CancellationToken, Object[])

Asynchronously finds an entity with the given primary key values. If an entity with the given primary key values exists in the context, then it is returned immediately without making a request to the store. Otherwise, a request is made to the store 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 in the context or the store, then null is returned.

FindAsync(Object[])

Asynchronously finds an entity with the given primary key values. If an entity with the given primary key values exists in the context, then it is returned immediately without making a request to the store. Otherwise, a request is made to the store 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 in the context or the store, then null is returned.

FindAsync(CancellationToken, Object[])

Asynchronously finds an entity with the given primary key values. If an entity with the given primary key values exists in the context, then it is returned immediately without making a request to the store. Otherwise, a request is made to the store 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 in the context or the store, then null is returned.

public virtual System.Threading.Tasks.Task<TEntity> FindAsync (System.Threading.CancellationToken cancellationToken, params object[] keyValues);
abstract member FindAsync : System.Threading.CancellationToken * obj[] -> System.Threading.Tasks.Task<'Entity (requires 'Entity : null)>
override this.FindAsync : System.Threading.CancellationToken * obj[] -> System.Threading.Tasks.Task<'Entity (requires 'Entity : null)>

Parameters

cancellationToken
CancellationToken

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

keyValues
Object[]

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

Returns

Task<TEntity>

A task that represents the asynchronous find operation. The task result contains the entity found, or null.

Exceptions

Thrown if the context has been disposed.

Remarks

The ordering of composite key values is as defined in the EDM, which is in turn as defined in the designer, by the Code First fluent API, or by the DataMember attribute. Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context.

Applies to

FindAsync(Object[])

Asynchronously finds an entity with the given primary key values. If an entity with the given primary key values exists in the context, then it is returned immediately without making a request to the store. Otherwise, a request is made to the store 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 in the context or the store, then null is returned.

public virtual System.Threading.Tasks.Task<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)>
Public Overridable Function FindAsync (ParamArray keyValues As Object()) As Task(Of TEntity)

Parameters

keyValues
Object[]

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

Returns

Task<TEntity>

A task that represents the asynchronous find operation. The task result contains the entity found, or null.

Remarks

The ordering of composite key values is as defined in the EDM, which is in turn as defined in the designer, by the Code First fluent API, or by the DataMember attribute. Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context.

Applies to