Last but not least, we need to make some changes to the QuizController
to make it use the ApplicationDbContext
to retrieve data instead of those Dummy Data Provider strategies we implemented back in Chapter 2, Backend with .NET Core.
In order to do that, the first thing we need to do is to find an efficient way to map each Quiz
entity to a corresponding QuizViewModel
object, as our new Data Provider won’t generate them anymore. We can achieve such a result in a number of ways, including the following:
- Adding a
Helper Method
, such asGetQuizViewModel(Quiz quiz)
, thus handling the mapping manually with a few lines of code - Adding a
Constructor Method
to theQuizViewModel
itself, such asQuizViewModel(Quiz quiz)
, doing pretty much the same thing as the aforementioned helper method - Adding one of the many Object-to-Object Auto-Mapping Tools freely available via NuGet and configuring it to handle the mapping automatically whenever we need it
We’ll definitely go for the latter...