liveBook · Manning

Entity Framework Core

As explained in Building Web APIs with ASP.NET Core

Entity Framework Core is a cross-platform object-relational mapper for .NET that enables applications to work with databases using .NET objects.

Entity Framework Core (EF Core) is a lightweight, extensible, cross-platform object-relational mapper for .NET. It lets an ASP.NET Core web API work with relational database data through C# objects and ORM techniques instead of hand-written SQL queries. section 4.0 section 4.3

A practical EF Core setup for a web API follows these steps:

  • Choose a DBMS, such as a local Microsoft SQL Server Express instance or a cloud-hosted service. section 4.0 section 4.5
  • Define entity classes that represent database tables and support CRUD operations from application code. section 4.5
  • Create an ApplicationDbContext to represent the operational connection between ASP.NET Core and the database. section 4.5
  • Configure the context with a connection string, storing development secrets through Visual Studio Secret Manager. section 4.5
  • Use EF Core migrations to generate the database structure from the current data model. section 4.5

Applying EF Core to a board-game API

Replace the MyBGList web API's on-demand fake data with a DBMS-backed data source. Use ApplicationDbContext and entity classes to perform create, read, update, and delete operations; express those operations with LINQ and IQueryable<T> rather than requiring specific SQL knowledge. section 4.0 section 5.0

EF Core supports both database-first development, which generates a data model from an existing schema, and code-first development, which generates a schema from a manually created model. ORM usage can improve security, flexibility, optimization, readability, and maintainability, although raw SQL may still have drawbacks to weigh. section 4.0 section 4.5

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Explains ORM use, models, contexts, connection strings, migrations, and CRUD, while assuming basic DML knowledge.
Examples
Uses a MyBGList web API, SQL Server Express, SSMS, entity classes, ApplicationDbContext, Secret Manager, and migrations.
What it assumes
Assumes basic DBMS data-manipulation operations, but requires no specific SQL knowledge because LINQ handles the demonstrated tasks.
What you can do after
Build and operate a database-backed ASP.NET Core API using entities, ApplicationDbContext, LINQ, CRUD operations, and migrations.
How it connects
Connects DBMS, database schemas, entity classes, ApplicationDbContext, ORM, LINQ, IQueryable, migrations, and CRUD operations.

Also explained in

Compare how 4 books explain Entity Framework Core →

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.