Saving data

The DbContext class provided by EF Core is designed to work as a Unit Of Work (https://martinfowler.com/eaaCatalog/unitOfWork.html) that stores and tracks all the objects in the model. As a Unit Of WorkDbContext lets you add an object for tracking, and then we set the EntityState parameter of the object so that DbContext can perform the correct database operation (INSERT, UPDATE, or DELETE) when needed—that is, when calling the Save() or SaveAsync() methods. 

When defining your instance of DbContext, you added properties of the DbContext type for each entity you wanted your model to include. The DbContext is a special type of collection that is aware of the EntityState objects, and lets you control them with simple methods ...

Get Hands-On Full-Stack Web Development with ASP.NET Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.