DbSet<TEntity>.Find(Object[]) Method

Definition

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 TEntity Find (params object[] keyValues);
public virtual TEntity? Find (params object?[]? keyValues);
abstract member Find : obj[] -> 'Entity
override this.Find : obj[] -> 'Entity
Public Overridable Function Find (ParamArray keyValues As Object()) As TEntity

Parameters

keyValues
Object[]

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

Returns

TEntity

The entity found, or null.

Remarks

See Using Find and FindAsync for more information and examples.

Applies to