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.

35 posts
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 ...

How I Reduced API Response Time by 70% in a Large .NET Project

Slow APIs hurt users' experience and the owners' pocket. Users become disappointed, and the server costs more if APIs are not up to standard in large projects. I also faced a similar issue in my project. However, I cut down the performance overhead marginally. This article breaks down ...

Implementing Audit Logs in EF Core Without Polluting Your Entities

Most modern applications require the historical audit logging of changes made to database entities. The audit log provides you with insights into all changes made, including their timestamps and the users responsible for those changes. The logs ensure transparency, allowing stakeholders to observe what changes were made to business-critical data, ...

Exploring Source Generators in C#: Real-World Examples

Tired of writing the same class scaffolding over and over? Annoyed by how much time you spend on "glue code" instead of actual features? You're not alone. Imagine if the C# compiler does this on your behalf every time, perfectly. Let me introduce you to C# ...

Using Result<T> or OneOf<T> for Better Error Handling in .NET

Are you tired of debugging vague errors or overusing try-catch? Traditional exception-based workflows can be messy, highly compromising code readability and maintainability. In this post, I will introduce you to Result<T> and OneOf<T>. Two powerful patterns that make success and failure contracts explicit. Whether ...

Lesser-known C# features that can simplify your code

C# is a robust OOP language that provides the foundation for building almost every application with .NET. As a C# developer, you are likely familiar with its fundamentals. However, like any legacy technology, it holds more depth to explore and enhance your code's maintainability and beauty. In this ...

16 common mistakes C#/.NET developers make (and how to avoid them)

As developers, we often fall into common pitfalls that impact the performance, security, and scalability of our applications. From neglecting data validation to overengineering, and from ignoring async/await to mishandling resource disposal, even experienced C# developers can make these mistakes. In this post, I've gathered some of ...

IEnumerable vs. IAsyncEnumerable in .NET: Streaming vs. Buffering

You've likely used IEnumerable<T> with EF Core while fetching data from a database. However, have you ever wondered how it loads data from your data set, and if IEnumerable will work fine when the application grows? To find answers, I will break down the core ...

Storing JSON data in relational databases using EF Core

JavaScript Object Notation (JSON) is a great fit when you are working with logs, configuration settings, or other flexible data structures. JSON represents data in a human-readable format that many modern applications can parse easily. In this article, you will learn how to store and manage JSON data in relational ...