DbContext
is the primary class responsible for interacting with the database. It represents a session with the database and acts as a Unit of Work pattern implementation.
Key responsibilities:
public class ApplicationDbContext : DbContext
{
public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("connection-string");
}
}