In this post will are going to finally create the database that we have been preparing for in the last previous blog posts. It's a two step process, first you have to add the NorthwindContext to the application in the Startup class, then you have to run the Entity Framework migration tool.
Here are the steps to create your NorthwindCafe database:
1. Open the Startup.cs file, then type the following lines in the ConfigureServices method
var connectionString = Configuration["Data:NorthwindContextConnection"];
services.AddDbContext<NorthwindContext>(options => options.UseSqlServer(connectionString));
The line above gets the connection string from the appSettings.json file that we've created earlier. Then use the AddDbContext method in the services instance. Dependency injection will take care of the plumbing for you. Using lamba expression we tell the Entity Framework to use the Sql Sever provider for Entity Framework core.
Make sure you have the following namespaces in your Startup class
using NorthwindCafe.Web.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;