chapter five
5 Setting up a project and database with Entity Framework Core
This chapter covers
- Refactoring a legacy code base to be clean and secure
- Using Entity Framework Core to query a database
- Implementing the Repository/Service Pattern
- Creating a new .NET 5 solution and project using the command line.
The time has finally come. You are probably eager to fix some of the issues we saw in chapters 3 and 4, and now we get to do that. First things first, let’s come up with a game plan on how to tackle this refactor. We already know a couple of things that we need to do differently:
- o In chapter 3 we were told to use .NET 5 instead of the .NET Framework for the new version of the Flying Dutchman Airlines service.
- o We need to rewrite the endpoints to be clean code (in particular, adhering to the DRY principle). This allows the airline to be more resilient against future scalability and extensibility problems.
- o There is a security vulnerability relating to how we treat the connection string; we need to fix that. The security vulnerability is a hard-coded connection string.
- o The object names do not match the database column names. We should fix that to ensure a perfect isomorphic relationship between the codebase and the database.
- o We need to adhere to the OpenAPI file discussed in chapter 2 and shown in Appendix D.