Ali Hamza Ansari

Ali Hamza Ansari

Meet Ali, a talented .NET developer from Pakistan. Besides blogging, Ali works for a range of international customers doing everything from C# to Azure.

43 posts
Building Read Models with EF Core Projections

You can't really argue against the importance of performance in any application. Even if the system is not time-critical, efficient and time-saving operations are cornerstones of the system. Data fetching is the primary step for improving the performance of most applications. If you use Entity Framework Core (EF ...

Working with Excel files in .NET: OpenXML vs EPPlus vs ClosedXML

If you have ever had to generate Excel reports in C#-based applications, you know the pain of choosing from too many libraries with too many tradeoffs. Some are extremely powerful but painful to write, while others are friendly but struggle with large files. You probably come across OpenXML, EPPlus, ...

Repository pattern vs Specification: Which is more maintainable?

When talking about Domain-Driven Design (DDD), the repository pattern becomes a default choice for the data access layer. Another pattern is the Specification pattern that organizes code into smaller objects. The question raised here is which suits your project and which is more maintainable as your project scales? I will ...

How .NET Garbage Collector works (and when you should care)

In the world of .NET, memory management is an important aspect of any application. Fortunately, you don't have to shoulder this immense task yourself. .NET handles it with the superpower of the Garbage Collector (GC). A GC is an engine that keeps your app fast, responsive, and resource-efficient. ...

Hidden Costs of Boxing in C#: How to Detect and Avoid Them

C# Boxing and Unboxing are vital players in the performance of an application. However, they are often overlooked. They involve heap allocations that bring a penalty due to their accessing mechanism. In today's post, we will unfold Boxing and Unboxing in detail, study how they are costly to ...

Expression Trees in C#: Building Dynamic LINQ Queries at Runtime

Tired of endless if-else blocks just to build queries? What if your LINQ queries could write themselves at runtime? Today, we will unfold expression trees, which can be used to create dynamic queries at runtime. I will show how to use expression trees in your project and understand their advantages ...

Demystifying async void in C#: Why It's Dangerous and When It's Okay

Async operations are an integral part of any application. In C#, mostly asynchronous methods return Task or Task<T>, but there's also the odd case of async void. We know void is for synchronous operations, so why does C# even allow async void? I will dissect ...

Visualizing LINQ Queries with LINQPad: Boost Your EF Core Debugging

Ever feel exhausted debugging a complex EF Core query? Do you wonder what went wrong in the EF Core LINQ query spaghetti that hinders the results? At one end, EF Core and LINQ accelerate the development speed and make it easy to communicate with a database. However, its intermediate results ...

Mastering Incremental Source Generators in C#: A Complete Guide with Example

In the Previous blog, I discussed source generators. .NET has introduced an improved version of a source generator, called Incremental Source Generator. The new type generates code faster and reduces the code, improving readability. In this post, I will introduce the new type of source generator and compare it to ...