Using Entity Framework Core with ASP.NET Core
Entity Framework Core is a natural way to get real data into 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 SQLite and/or SQL Server. 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 are needed by ASP.NET Core 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.Common.DataContext
project for either SQLite or SQL Server, as shown in the following markup:<!-- change Sqlite to SqlServer if you prefer --> <ItemGroup> <...