Search⌘ K
AI Features

Using Entity Framework Core with ASP.NET Core

Explore how to integrate Entity Framework Core into an ASP.NET Core Razor Pages project. Learn to register database contexts as services, reference entity models, and bind data dynamically in web pages using SQLite or SQL Server for real data access.

Entity Framework Core is a natural way to get real data into a website. Earlier, we created two pairs of class libraries: one for the entity models and one for the Northwind database context for SQLite and/or SQL Server. We will now use them in our website project.

Configuring Entity Framework Core as a service

Functionality, such as Entity Framework Core database contexts, that ASP.NET Core needs should be registered as a dependency service during website startup. The code below uses SQLite, but we can easily use SQL Server if we prefer.

Let’s see how:

Step 1: In the Northwind.Web ...