Creating the database

Now that we have our own DbContext and a valid Connection String, we can easily add the initial migration and create our database.

Updating Startup.cs

The first thing we have to do is add the EF support and our ApplicationDbContext implementation to our application startup class. Open the Startup.cs file and update the ConfigureServices method in the following way (new lines are highlighted):

 
public void ConfigureServices(IServiceCollection services) 
{ 
    // Add framework services. 
    services.AddMvc(); 
 
    // Add EntityFramework's Identity support.

    services.AddEntityFramework();

    // Add ApplicationDbContext.

    services.AddDbContext<ApplicationDbContext>(options =>
 options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]) ...

Get ASP.NET Core: Cloud-ready, Enterprise Web Application Development 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.