How to do it...

  1. First, we add EF as an injected service:
public void ConfigureServices(IServiceCollection services) 
{ 
services.AddEntityFramework()}

IntelliSense can help us to find this method, which already exists as an extension method helper.

  1. Next, we associate EF with a database. EF doesn't know anything about the data store we will use (any relational database, any nonrelational database, and so on):
public void ConfigureServices(IServiceCollection services) 
{ 
services.AddEntityFramework() 
.AddSqlServer() }
  1. Now we add the DbContext named ApplicationDbContext associated with the connection in the parameter stored in appsettings.json.

In doing this, we configure a database provider when setting up the services for our application: ...

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.