Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

DbContext.Find Method

Definition

Namespace:
Microsoft.EntityFrameworkCore
Assembly:
Microsoft.EntityFrameworkCore.dll
Package:
Microsoft.EntityFrameworkCore v1.1.6
Package:
Microsoft.EntityFrameworkCore v10.0.0
Package:
Microsoft.EntityFrameworkCore v2.0.3
Package:
Microsoft.EntityFrameworkCore v2.1.11
Package:
Microsoft.EntityFrameworkCore v2.2.6
Package:
Microsoft.EntityFrameworkCore v3.0.0
Package:
Microsoft.EntityFrameworkCore v3.1.0
Package:
Microsoft.EntityFrameworkCore v5.0.0
Package:
Microsoft.EntityFrameworkCore v6.0.0
Package:
Microsoft.EntityFrameworkCore v7.0.0
Package:
Microsoft.EntityFrameworkCore v8.0.0
Package:
Microsoft.EntityFrameworkCore v9.0.0

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Overloads

Name Description
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
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
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


Feedback

Was this page helpful?