Querying and updating data with Entity Framework Core
To test our DB layer, we need to add a console project based on the same .NET Core version as our library to the solution. Let’s get started:
- Let’s call the new console project
WWTravelClubDBTest
- Now, we need to add our data layer as a dependency of the console project by right-clicking on the Dependencies node of the console project and selecting Add Project Reference
- Remove the content of the
Program.cs
file and start by writing the following:Console.WriteLine("program start: populate database, press a key to continue"); Console.ReadKey();
- Then, add the following namespaces at the top of the file:
using WWTravelClubDB; using WWTravelClubDB.Models; using Microsoft.EntityFrameworkCore; using WWTravelClubDBTest;
Now that we have finished preparing our test project, we can experiment with queries and data updates. Let’s start by...