A visualization illustrating how Split Queries solve Cartesian Explosion in EF Core

Split Queries in EF Core: Mitigating Cartesian Explosion

Have you worked with Split Queries in EF Core before? When you incorporate related tables using EF Core, it typically generates a JOIN query, potentially leading to duplicated data. While this duplication is usually insignificant for small datasets, it can become problematic when dealing with larger volumes. When multiple collections are included, SQL JOINs multiply rows exponentially, not linearly. 1 2 3 4 var posts = context.Posts .Include(p => p.Comments) .Include(p => p.Tags) .ToList(); Imagine a scenario where you have a table with 1000 posts and each post has 1000 comments. If you use the query below, you will get 1000 * 1000 = 1,000,000 rows in the result. This phenomenon is known as Cartesian Explosion, causing unexpected spikes in data loads. ...

February 15, 2025 路 2 min 路 350 words 路 Eduardo Potumati
A code comparison showing a foreach loop converted into a LINQ expression

Convert a foreach Loop to LINQ

Convert a foreach loop to LINQ LINQ transforms a query into a first-class language construct in C#. It can reduce the amount of code, enhance readability, and enable similar query expression patterns across different data sources. 馃憠 Adapted from my original post on LinkedIn .

November 15, 2024 路 1 min 路 45 words 路 Eduardo Potumati