Entity Framework makes it really easy to fetch related data. For example let’s get all the Customers with their ordered products.
This involves 3 entities: Customer –> Order –> Product.
To fetch this in one go in EF Core, you can use the following LINQ query:
On the database this will end up in a query like this:
The problem is that this results in a cartesian product as the customer data is duplicated for every ordered product in the result set.
A solution exists in EF Core through the AsSplitQuery
method that allows Entity Framework to split each related entity into a query on each table:
More information: https://docs.microsoft.com/en-us/ef/core/querying/single-split-queries