Using Entity Framework Core with ASP.NET Core
Entity Framework Core is a natural way to get real data into a website. In Chapter 13, Introducing Practical Applications of C# and .NET, you created two pairs of class libraries: one for the entity models and one for the Northwind database context, for either SQL Server or SQLite or both. You will now use them in your website project.
Configure Entity Framework Core as a service
Functionality such as Entity Framework Core database contexts that are needed by ASP.NET Core must be registered as a 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> <ProjectReference...