Using Entity Framework Core with ASP.NET Core
Entity Framework Core is a natural way to get real data onto a website. In Chapter 12, Introducing Web Development Using ASP.NET Core, you created two pairs of class libraries: one for the entity models and one for the Northwind database context, for SQL Server and SQLite. You will now use them in your website project.
Configuring Entity Framework Core as a service
Functionality, such as Entity Framework Core database contexts, that is needed by an ASP.NET Core project should be registered as a dependency service during website startup. The code in the GitHub repository solution and below uses SQLite, but you can easily use SQL Server if you prefer.
Let’s see how:
- In the
Northwind.Web
project, add a project reference to theNorthwind.DataContext
project for either SQLite or SQL Server, as shown in the following markup:<!-- Change Sqlite to SqlServer if you prefer. --> <ItemGroup> <...