C# – Map query results to multiple objects with Dapper

When you’re querying joined tables, you can map each row to multiple objects by using the multi mapping feature in Dapper. To multi map, you have to provide Dapper with the following: Which types to map to. Which column(s) to split on. This tells Dapper which columns it should try to map to which type. … Read more

EF Core – Inheritance mapping

There are two ways to do inheritance mapping in EF Core: Table-per-Hierarchy (TPH) = There’s a single table for all classes in the hierarchy. Table-per-Type (TPT) = There’s one table per class in the hierarchy. This is available in EF Core 5 and above. Let’s say we have a database with employees. All employees have … Read more

EF Core – SELECT queries involving multiple tables

When you have tables that are related, you’ll often need to get data from both tables at once, or filter records from one table based on values in another table. In this article, I’ll show examples of executing queries like this where more than one table is involved. You can do most queries using LINQ. … Read more

KeyNotFoundException: The given key was not present in the dictionary

Problem The following exception is thrown when you try to get a value from a dictionary using a key that doesn’t exist in the dictionary: KeyNotFoundException: ‘The given key was not present in the dictionary.’ Consider the following the example: When the user enters a city name that isn’t in the dictionary, such as “New … Read more