Share via


DbContext.Find Method

Definition

Overloads

Find(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 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.

Find<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 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.

Find(Type, Object[])

Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.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 object Find (Type entityType, params object[] keyValues);
public virtual object? Find (Type entityType, params object?[]? keyValues);
abstract member Find : Type * obj[] -> obj
override this.Find : Type * obj[] -> obj
Public Overridable Function Find (entityType As Type, ParamArray keyValues As Object()) As Object

Parameters

entityType
Type

The type of entity to find.

keyValues
Object[]

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

Returns

The entity found, or null.

Remarks

See Using Find and FindAsync for more information and examples.

Applies to

Find<TEntity>(Object[])

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

Type Parameters

TEntity

The type of entity to find.

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