August 2017
Intermediate to advanced
330 pages
7h 26m
English
To connect to a database application, one needs a connection string; just like the preceding examples of EF6 and Dapper, add connection string details in the appsettings.json file as follows:
{
"ConnectionStrings": {
"SqlDbConnStr": "Server=.\\sqlexpress;initial catalog=PacktContactsDB;Trusted_Connection=True;"
}
}
The ContactsContext method needs to be added to the services collection in the Startup class by reading the database connection string:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddDbContext<ContactsContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString( "SqlDbConnStr")));
services.AddMvc();
}
Read now
Unlock full access