liveBook · Manning

Dbcontext

DbContext is the Entity Framework Core class that coordinates database access, entity querying and change tracking, and persistence for an application’s data model.

How 4 Manning books explain it

ASP.NET Core in Action, 3e

DbContext is the Entity Framework Core base class that coordinates database connections, entity tracking, querying, and persistence for a data model.

How it is used
Coordinates EF Core’s data model and runtime database access for application entities.
How deep it goes
Works through context definition, registration, migrations, and tracked updates, while leaving detailed convention customization and alternative tracking mechanisms to documentation.
Examples
Uses a recipe-and-ingredient context, a tracked recipe update, an Identity context, and scoped access from a background service.
What you can do after
Build it from scratch with EF Core by defining and registering a context, migrating its schema, and loading and saving entities.

Read how ASP.NET Core in Action, 3e explains dbcontext →

Building Web APIs with ASP.NET Core

DbContext is the Entity Framework Core class that coordinates database queries, entity tracking, and persistence for an application session.

How it is used
Provides the database session used by an ASP.NET Core controller to query board games instead of returning dummy data.
How deep it goes
Walks through subclass creation, model configuration, service registration, controller injection, and query execution; it does not detail EF Core internals.
Examples
Uses an ApplicationDbContext, SQL Server registration, and a board-game controller GET action that replaces generated data with a database query.
What you can do after
Apply it via Entity Framework Core to register a context, inject it into a controller, and retrieve board-game entities.

Read how Building Web APIs with ASP.NET Core explains dbcontext →

.NET in Action, Second Edition

DbContext is the Entity Framework Core class that coordinates entity operations, querying, change tracking, and persistence for a data model.

How it is used
Coordinates entity persistence and queries in a catalog application and its ASP.NET Core API.
How deep it goes
Builds a context, demonstrates its lifetime and registration, and revises provider configuration; stops short of change-tracking internals.
Examples
Uses a book catalog that seeds books, fetches books with ratings, and serves them through controller actions.
What you can do after
Build it from scratch as an EF Core context, then operate it in queries and configure its lifetime in an API.

Read how .NET in Action, Second Edition explains dbcontext →

Pro ASP.NET Core 7, Tenth Edition

DbContext is the Entity Framework Core base class that provides database access, entity tracking, and persistence services for a data context.

How it is used
Provides database access to ASP.NET Core request handlers through an Entity Framework Core context registered as a service.
How deep it goes
Builds and configures derived contexts, then demonstrates querying and saving; does not detail DbContext internals.
Examples
Uses product and calculation contexts, a calculation endpoint, SQL logs, and a supplier query that triggers an object-cycle exception.
What you can do after
Build it from scratch: define a derived context, register its SQL Server connection, and use it to query and save entities.

Read how Pro ASP.NET Core 7, Tenth Edition explains dbcontext →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.