O'Reilly logo

ASP.NET Core: Cloud-ready, Enterprise Web Application Development by James Singleton, Valerio De Sanctis, Mugilan T. S. Ragupathi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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"]) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required