...

/

Using Entity Framework Core with ASP.NET Core

Using Entity Framework Core with ASP.NET Core

Learn about configuring Entity Framework Core as a service in ASP.NET Core and registering database contexts.

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 project, add a project reference ...