DbSet<TEntity>.FindAsync Method
Assembly: EntityFramework (in EntityFramework.dll)
Name | Description | |
---|---|---|
![]() | 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. |
DbSet<TEntity>.FindAsync Method (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 Task<TEntity> FindAsync( CancellationToken cancellationToken, params object[] keyValues )
Parameters
- cancellationToken
-
Type:
System.Threading.CancellationToken
A CancellationToken to observe while waiting for the task to complete.
- keyValues
-
Type:
System.Object[]
The values of the primary key for the entity to be found.
Return Value
Type: System.Threading.Tasks.Task<TEntity>A task that represents the asynchronous find operation. The task result contains the entity found, or null.
Exception | Condition |
---|---|
InvalidOperationException | Thrown if multiple entities exist in the context with the primary key values given. |
InvalidOperationException | Thrown if the type of entity is not part of the data model for this context. |
InvalidOperationException | Thrown if the types of the key values do not match the types of the key values for the entity type to be found. |
InvalidOperationException | Thrown if the context has been disposed. |
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.
DbSet<TEntity>.FindAsync Method (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.
Parameters
- keyValues
-
Type:
System.Object[]
The values of the primary key for the entity to be found.
Return Value
Type: System.Threading.Tasks.Task<TEntity>A task that represents the asynchronous find operation. The task result contains the entity found, or null.
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.