DbContext.FindAsync DbContext.FindAsync Method

Definition

Overloads

FindAsync(Type, Object[]) FindAsync(Type, 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 dataabse 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(Type, Object[], CancellationToken) FindAsync(Type, 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 dataabse 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<TEntity>(Object[]) FindAsync(Of TEntity)(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 dataabse 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<TEntity>(Object[], CancellationToken) FindAsync(Of TEntity)(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 dataabse 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(Type, Object[]) FindAsync(Type, 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 dataabse 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 Task<object> FindAsync(Type entityType, params object[] keyValues)
Public Overridable Function FindAsync(entityType As Type, ParamArray keyValues As Object()) As Task(Of Object)

Parameters

entityType
System.Type System.Type

The type of entity to find.

keyValues
System.Object[] System.Object()

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

Returns

System.Threading.Tasks.Task<System.Object> System.Threading.Tasks.Task(Of System.Object)

The entity found, or null.

FindAsync(Type, Object[], CancellationToken) FindAsync(Type, 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 dataabse 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 Task<object> FindAsync(Type entityType, object[] keyValues, CancellationToken cancellationToken)
Public Overridable Function FindAsync(entityType As Type, keyValues As Object(), cancellationToken As CancellationToken) As Task(Of Object)

Parameters

entityType
System.Type System.Type

The type of entity to find.

keyValues
System.Object[] System.Object()

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

cancellationToken
System.Threading.CancellationToken System.Threading.CancellationToken

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

Returns

System.Threading.Tasks.Task<System.Object> System.Threading.Tasks.Task(Of System.Object)

The entity found, or null.

FindAsync<TEntity>(Object[]) FindAsync(Of TEntity)(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 dataabse 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 Task<TEntity> FindAsync<TEntity>(params object[] keyValues)where TEntity : class
Public Overridable Function FindAsync(Of TEntity As Class)(ParamArray keyValues As Object()) As Task(Of TEntity)

Type Parameters

TEntity

The type of entity to find.

Parameters

keyValues
System.Object[] System.Object()

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

Returns

System.Threading.Tasks.Task<TEntity> System.Threading.Tasks.Task(Of TEntity)

The entity found, or null.

FindAsync<TEntity>(Object[], CancellationToken) FindAsync(Of TEntity)(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 dataabse 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 Task<TEntity> FindAsync<TEntity>(object[] keyValues, CancellationToken cancellationToken)where TEntity : class
Public Overridable Function FindAsync(Of TEntity As Class)(keyValues As Object(), cancellationToken As CancellationToken) As Task(Of TEntity)

Type Parameters

TEntity

The type of entity to find.

Parameters

keyValues
System.Object[] System.Object()

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

cancellationToken
System.Threading.CancellationToken System.Threading.CancellationToken

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

Returns

System.Threading.Tasks.Task<TEntity> System.Threading.Tasks.Task(Of TEntity)

The entity found, or null.