A new feature that was added on Entity Framework Core 5, it’s the possibility to create a Table-per-Type (TPT) mapping. In this article, I explain the difference between the Table-per-Hierarchy (TPH) mapping and the Table-per-Type (TPT) mapping.

By default, EF Core maps an inheritance hierarchy of .NET types to a single table in the database, to store the data for all types in the hierarchy, and a discriminator column is used to identify which type each row represents, this is known as Table-per-Hierarchy (TPH) mapping.

With EF Core 5, it’s also possible to map each .NET type in an inheritance…


A new feature on Entity Framework Core 5, it’s the possibility to split a query into multiple SQL queries. On EF Core 3.0 for example, a single query was generated for each LINQ query, but now on EF Core 5, there is the possibility to split the query. In this article, I will explain the difference between them.

To show the differences between the default query and the split query, I’ve created a console application using .NET Core 5.0, and I’ve installed the packages:

  • Microsoft.EntityFrameworkCore.Design 5.0.3
  • Microsoft.EntityFrameworkCore.SqlServer 5.0.3
  • Microsoft.EntityFrameworkCore.Tools 5.0.3

On the Startup class, in the method OnConfiguring, I enabled…


In this article, we will migrate a WEB API application from .NET Core 3.1 to .NET 5.0.

Prerequisites

For this migration, I will be using Visual Studio. The first step it’s necessary to do is:

  • download the Visual Studio 2019 16.8 or later, with the ASP.NET and web development workload. Visual Studio 2019 can be downloaded here.
  • Download .NET 5.0 SDK or later, which can be downloaded here.

For this example, I’m using a project that can be found on my GitHub at this repository: https://github.com/henriquesd/MigratingFromDotNet3.1To5.0

Open the solution with Visual Studio, right-click on the project, click on “Properties”, and…


Dependency Injection (DI) is a design pattern which supports the development of loosely coupled code, and it’s also one of the SOLID principles (Dependency Inversion Principle). On this article, I will explain how we can use Dependency Injection and what is the difference between the three services lifetimes that can be used in .NET Core applications.

“Dependency Injection (DI) is a technique that provides dependencies to a class, thereby achieving dependency inversion. Dependencies are passed (injected) to a client that needs it.”

DI is used a lot in .NET Core applications, and also the own framework brings it natively. …


In this article we are going to see how to create the unit tests for the Repository classes in the Infrastructure layer, using an In-Memory database.

The Repository classes are responsible for handle the data into the database. There are at least three ways to create unit tests for these classes, one way is using a real database, which I do not recommend because the tests must be isolated from each other, and to do that it would be necessary to create a new database for each test, but this will make the tests run very slow. Another way is…


A new feature that is released with the new version of the Entity Framework Core is the possibility to create a Many-to-Many relationship without explicitly mapping the join table. On this article, we are going to see how we can create a Many-to-Many relationship using Entity Framework Core 5.

On the previous versions of EF Core, to create a many-to-many relationship, it’s necessary to have a third entity. For example, to create a many-to-many relationship between the entity Actor and the entity Movie, it is necessary to have three entities: Actor, Movie, and ActorMovie. On the article “Entity Framework Core…


In this article we are going to see how to create the unit tests for the Controllers in the API layer. To create these unit tests we are also going to use the xUnit and Moq framework.

Creating the Unit Test project for the API layer

Let’s start creating a new xUnit project for the API layer, similar to the one we created for the domain layer in the previous article (you can read the previous article clicking here). Open the solution with Visual Studio, and create a new xUnit project and add it on the “test” folder:


In this article we are going to see how we can create the unit tests for the Services classes in the Domain layer, using xUnit framework.

The three most commons unit test frameworks for .NET are:

  • XUnit — The newest from this list. It was written by the original inventor of NUnit v2. This framework is used by the development team of .NET Core and ASP.NET.
  • NUnit — A JUnit version for .NET.
  • MSTest — Framework from Microsoft.

The goal of the unit test, it’s to verify each unit from the software, in isolation, to guarantee that each unit of…


Having automated tests on the application gives us a lot of benefits, even so, it’s not uncommon to see software that does not have tests ou hear someone saying that tests are not necessary. Tests are used in many kinds of industries, like cars, medicines, and others. The products are constantly tested by the companies to ensure that the product or service that they are offering are safe and work correctly. In software industries, this should not be different.

The software should have automated tests to ensure the good quality and warranty that the software is doing exactly what it…


When we deal with casting, there are situations where an Exception can be thrown. For example, if the type of the object in memory does not match the cast, the runtime will throw a System.InvalidCastException. For example:

This code will compile but will throw an exception at runtime. To avoid this kind of error, we can use the is and as operators which are provided by C# and can help us to perform casting operations in a more elegant way.

The is Operator

The is operator is used to checking if the run-time type of an object is compatible…

Henrique Siebert Domareski

.NET Full-Stack Developer | C# | .NET | .NET CORE | ASP.NET MVC | Unit Test | Angular

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store