Entity Creation for New API Project

Monday, November 4, 2024 – Last week,  which was a short week for me, I focused on building entities for our new API project. My first step was to review our entity-relationship diagram (ERD), a clear diagram we rely on for a clear visual structure of the database. This diagram, equipped with attributes and data types, serves as a reference point for any updates or improvements to the database. After double-checking data types and discussing potential enhancements with my colleague, I proceeded with entity creation within the project.

When defining entity models, I intentionally saved relationship configurations for last to avoid complications, allowing me to focus on careful assignments. After adding a migration, my initial attempt failed, so I reviewed and corrected some errors. Once the migration was successful, I moved on to developing CRUD operations, starting with a “Read by ID” query since it’s the most straightforward. Building the repository required extra attention as, unlike previous projects using EF Core, this one uses Dapper for database mapping, requiring SQL queries to be written manually. Since the entity I queried has a one-to-many relationship with another entity, I researched the practices for crafting SQL queries in such cases.

Before advancing further in the CRUD process, I created a unit test for the query. Running tests allowed me to debug and identify issues in my code and query. Mr Peter also provided valuable advice on tracing errors within the query based on error messages. By the end of the week, I successfully passed the test and plan to expand the test scenarios next week before proceeding to the next CRUD operation.