A DbSet<T> is the Entity Framework Core entry point for a set of entities of type T. If a BoardGame object represents one database record, a DbSet<BoardGame> represents the set of board-game records. It lets an application query that set and perform CRUD operations on it. section 4.3.3
Expose entity sets as public properties on a DbContext:
- Add a property such as `public DbSet<BoardGame> BoardGames => Set<BoardGame>();` to ApplicationDbContext. The property gives application code a named way to reach board games. section 4.3.3
- Add properties for the other entity types the context must expose, including Domain, Mechanic, and the two junction entities linking them to board games. 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 listing shows the five public DbSet properties together. Each property's generic type identifies its entity type; `Set<T>()` supplies the corresponding set. section 4.3.3
Query board games
`var query = _context.BoardGames.Where(b => b.Year == 2020);` starts with a DbSet<BoardGame> and adds a LINQ filter. DbSet<T> implements IQueryable<T>, so LINQ operators can build a query representation. That query is sent to the database when it is executed, rather than when the variable is assigned. section 5.1.3
Add records from a CSV file
A CSV import checks for existing board games through `_context.BoardGames`, then adds new BoardGame, Domain, and Mechanic entities through their sets. Adding them does not immediately persist them: EF Core tracks the entities and their relationships in memory until `SaveChangesAsync()` saves them. section 5.3.5 section 5.3.5


