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 diagram or code snippet illustrating the Dependency Inversion Principle

Dependency Inversion (D) in SOLID: Why Is It So Important?

Dependency Inversion (D) in SOLID: Why Is It So Important? The Dependency Inversion Principle (D) reminds us that “high-level modules should not depend on low-level modules; both should depend on abstractions.” This means clients (code consuming functionalities) should rely on interfaces or abstractions, not concrete implementations. This practice reduces coupling, simplifies changes, and makes code more testable. For example, instead of directly coupling a notification service to a concrete class like EmailSender, use an interface such as IEmailSender. This allows you to easily swap implementations (e.g., SMTPClient, API service, message queue, etc) without modifying the client. ...

December 15, 2024 · 1 min · 124 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
Code snippet demonstrating how to compare two numbers using Math.Abs in C#

Comparing Numbers with Tolerance in C#

Comparing Numbers with Tolerance in C# Sometimes, when comparing two numbers in C#, you may want to allow for a tolerance or interval in the comparison. Instead of manually adding, subtracting, and comparing the values, you can use Math.Abs on the difference between the two numbers to check if the result falls within your acceptable range. 👉 Adapted from my original post on LinkedIn .

September 15, 2024 · 1 min · 65 words · Eduardo Potumati
Code snippet illustrating data transfer between controllers using TempData

TempData in ASP.NET Core: Transferring Data Between Controllers

TempData - Transfer data between controllers Ideal for transferring small amounts of data between controllers in ASP.NET MVC. Unlike ViewData and ViewBag, which are specific to a single view, TempData persists for one request cycle. This means the data remains available until it’s accessed, at which point it’s automatically removed. 👉 Adapted from my original post on LinkedIn .

August 15, 2024 · 1 min · 59 words · Eduardo Potumati
Code snippet illustrating the UseRewriter middleware in ASP.NET Core

Handling Duplicate URLs in ASP.NET MVC: www vs non-www

Concerned about duplicate URLs in ASP.NET MVC? Take care of both www and non-www domains. .NET already provides the correct method to handle them. Using the UseRewriter middleware is the optimal approach. You can use AddRedirectToNonWww() or AddRedirectToWww() for this purpose. 👉 Adapted from my original post on LinkedIn .

July 15, 2024 · 1 min · 50 words · Eduardo Potumati
Code snippet demonstrating how to use Reflection to read custom attributes in C#

Accessing Custom Attributes Using Reflection in C#

Accessing Custom Attributes Using Reflection in C# Custom attributes provide a powerful way to attach declarative metadata to your code-whether it’s on classes, methods, properties, or fields. But how do you actually read that metadata at runtime? This is where Reflection shines. By using the System.Reflection, you can dynamically inspect your code’s structure and retrieve the information defined within those custom attributes. This functionality is the backbone for creating highly flexible applications, such as automated validation frameworks, custom JSON serializers, or dynamic API routing systems. ...

June 15, 2024 · 1 min · 116 words · Eduardo Potumati
Code snippet demonstrating pattern matching to protect against nulls in C#

Pattern Matching in C#: Getting Protected from Nulls

Pattern Matching: Get Protected from Nulls C# pattern matching provides a substantially more concise syntax for testing expressions and taking decisive action when an expression matches. By leveraging these structural features, you can gracefully bundle type checks, variable declarations, and null validations into a single, highly readable statement-significantly reducing boilerplate code and the risk of unexpected NullReferenceExceptions. 👉 Adapted from my original post on LinkedIn .

May 15, 2024 · 1 min · 66 words · Eduardo Potumati
Code example illustrating Regex route constraints in ASP.NET Core MVC

Using Regular Expressions for ASP.NET MVC Routing

Using Regular Expressions (Regex) is a highly effective method for segmenting your ASP.NET MVC routing. With Regex route constraints, developers can create intricate matching patterns, leading to much more flexible and dynamic routing configurations directly in their controllers. Important: Always exercise caution when using System.Text.RegularExpressions to process untrusted input, as poorly constructed patterns can be vulnerable to Regular Expression Denial of Service (ReDoS) attacks. 👉 Adapted from my original post on LinkedIn . ...

April 15, 2024 · 1 min · 73 words · Eduardo Potumati
Code snippet demonstrating EF.Functions.Collate for accent-insensitive querying in EF Core

Handling Accents in SQL with EF Core

Have you ever needed to handle accents in SQL? If you are Latin, you have certainly done it many times. And how does it work in EF Core? It’s easy, you just have to use EF.Functions.Collate! Warning: Overriding case-sensitivity in a query via EF.Functions.Collate (or by calling string.ToLower) can have a very significant impact on your application’s performance. 🔗 Know more 👉 Adapted from my original post on LinkedIn . ...

March 15, 2024 · 1 min · 70 words · Eduardo Potumati