liveBook · Manning

SaveChanges

As explained in Building Web APIs with ASP.NET Core

SaveChanges is the Entity Framework Core method that persists tracked entity changes to the database.

SaveChanges is the Entity Framework Core method that persists tracked entity changes to the database. An action method typically loads entities through a DbContext, modifies them, and calls SaveChanges within the same unit of work. section 4.3.4

A typical update flow is:

  • Retrieve the records to modify; the resulting entities become tracked by the DbContext. section 4.3.4
  • Change the tracked entities, such as renaming each matching Mechanic in a foreach cycle. section 4.3.4
  • Call SaveChanges after the modifications; EF Core detects the changes and persists them in a batch. section 4.3.4

Batch rename request

An API action reads Mechanics matching an oldTerm value, changes their names to newTerm, calls SaveChanges, and returns details such as the number of modified records and task duration. section 4.3.4

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Explains retrieval, tracking, modification, change detection, persistence, and disposal, without detailing generated SQL internals.
Examples
Uses a batch rename of Mechanic entities as the concrete modification scenario.
What it assumes
Assumes familiarity with action methods and DbContext usage while demonstrating tracking within one unit of work.
What you can do after
Apply it via Entity Framework Core to persist tracked changes and report the update result from an API action.
How it connects
Connects DbContext, dependency injection, entity tracking, SELECT queries, and successful API responses.

Also explained in

Compare how 3 books explain SaveChanges →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.