DbContext.Set Method

Definition

Overloads

Set<TEntity>()

Creates a DbSet<TEntity> that can be used to query and save instances of TEntity.

Set<TEntity>(String)

Creates a DbSet<TEntity> for a shared-type entity type that can be used to query and save instances of TEntity.

Set<TEntity>()

Creates a DbSet<TEntity> that can be used to query and save instances of TEntity.

public virtual Microsoft.EntityFrameworkCore.DbSet<TEntity> Set<TEntity> () where TEntity : class;
abstract member Set : unit -> Microsoft.EntityFrameworkCore.DbSet<'Entity (requires 'Entity : null)> (requires 'Entity : null)
override this.Set : unit -> Microsoft.EntityFrameworkCore.DbSet<'Entity (requires 'Entity : null)> (requires 'Entity : null)
Public Overridable Function Set(Of TEntity As Class) () As DbSet(Of TEntity)

Type Parameters

TEntity

The type of entity for which a set should be returned.

Returns

A set for the given entity type.

Remarks

Entity Framework Core does not support multiple parallel operations being run on the same DbContext instance. This includes both parallel execution of async queries and any explicit concurrent use from multiple threads. Therefore, always await async calls immediately, or use separate DbContext instances for operations that execute in parallel. See Avoiding DbContext threading issues for more information and examples.

See Querying data with EF Core and Changing tracking for more information and examples.

Applies to

Set<TEntity>(String)

Creates a DbSet<TEntity> for a shared-type entity type that can be used to query and save instances of TEntity.

public virtual Microsoft.EntityFrameworkCore.DbSet<TEntity> Set<TEntity> (string name) where TEntity : class;
abstract member Set : string -> Microsoft.EntityFrameworkCore.DbSet<'Entity (requires 'Entity : null)> (requires 'Entity : null)
override this.Set : string -> Microsoft.EntityFrameworkCore.DbSet<'Entity (requires 'Entity : null)> (requires 'Entity : null)
Public Overridable Function Set(Of TEntity As Class) (name As String) As DbSet(Of TEntity)

Type Parameters

TEntity

The type of entity for which a set should be returned.

Parameters

name
String

The name for the shared-type entity type to use.

Returns

A set for the given entity type.

Remarks

Shared-type entity types are typically used for the join entity in many-to-many relationships.

See Querying data with EF Core, Changing tracking, and Shared entity types for more information and examples.

Applies to