DbSet<T> is an Entity Framework Core container for entities of one type. It makes those entities available through a DbContext for querying and create, read, update, and delete operations. As a useful analogy, if an entity represents a table record, its DbSet represents the table. section 4.3.3
A DbContext typically exposes a public DbSet property for each entity type. For a board-game API, ApplicationDbContext can expose BoardGames, Domains, Mechanics, and the junction entities that connect games to domains and mechanics. Each property uses Set<T>() to provide the corresponding set. section 4.3.3
using Microsoft.EntityFrameworkCore;
namespace MyBGList.Models
{
public class ApplicationDbContext : DbContext
{
// ... existing code
public DbSet<BoardGame> BoardGames => Set<BoardGame>();
public DbSet<Domain> Domains => Set<Domain>();
public DbSet<Mechanic> Mechanics => Set<Mechanic>();
public DbSet<BoardGames_Domains> BoardGames_Domains
=> Set<BoardGames_Domains>();
public DbSet<BoardGames_Mechanics> BoardGames_Mechanics => Set<BoardGames_Mechanics>();
}
}
The context exposes five entity sets, including sets for the two junction entities. section 4.3.3
DbSet<T> implements IQueryable<T>, so it can be the starting point for a LINQ query. Operators such as Where and OrderBy build a query representation; EF Core converts it to a database query when the IQueryable is executed. section 5.1.3
var query = _context.BoardGames .Where(b => b.Year == 2020) .OrderBy(b => b.Name);
This query selects games from 2020 and orders them by name. It can be executed later to retrieve the results. section 5.1.3
Importing board games
A CSV import reads existing games, domains, and mechanics into dictionaries, then skips records with missing required fields or duplicate game IDs. It adds new games to the BoardGames set, reuses or adds domains and mechanics, and creates junction entities for their relationships. EF Core tracks the additions in memory and assigns temporary keys; SaveChangesAsync persists the changes. section 5.3.5
When extending the model with categories, add sets for both the Category entity and its BoardGames_Categories junction entity. The relationship also needs navigation properties, foreign keys, and cascading rules. section 4.4.3


