Mastering Entity Framework Core 2.0
上QQ阅读APP看书,第一时间看更新

The appsettings.json setting

The application settings, as we explored earlier, are based on JSON, and in order to include a setting, we need to add a JSON key-value pair. In our case, ConnectionStrings is the key and the value is again a JSON object that defines DefaultConnection:

    {
"ConnectionStrings": {
"DefaultConnection": "Server=
(localdb)\\mssqllocaldb;Database=MasteringEFCoreDbFirst;
Trusted_Connection=True;MultipleActiveResultSets=true"

},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}

In this section, we have configured the database context in the ConfigureServices() method and also leveraged appsettings.json to make the connection configurable. At this point, all the configuration necessary is completed and EF is ready to consume the database for further implementation. Let's see how the CRUD operations could be performed using EF (we have already seen them in Chapter 1Kickstart - Introduction to Entity Framework Core, but still, we will explore a few parts with respect to rendering that which were not covered earlier).