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.

65 posts
New in .NET 10 and C# 14: EF Core 10's Faster Production Queries

Benchmarks EF Core 8 against EF Core 10 by querying a PostgreSQL Users table seeded with 200,000 rows through an AsNoTracking().Where().Select() minimal API endpoint, measuring a 25-50% speed boost in production data fetching from JIT inlining and row materialization improvements. ...

New in .NET 10 and C# 14: Optimizations in log aggregation jobs

Benchmarks parsing a JSON log entry's deviceId field with Newtonsoft.Json, System.Text.Json's JsonDocument, and the span-based Utf8JsonReader across .NET 8 and .NET 10 using BenchmarkDotNet, measuring 38% faster execution and lower allocations for high-volume log aggregation jobs. ...

Using Strategy Pattern with Dependency Injection in ASP.NET Core

Refactors an if-else DiscountService that hardcodes Regular (5%) and VIP (20%) discount math into an IDiscountStrategy interface with separate strategy classes, then wires the right strategy into ASP.NET Core's DI container so adding a new membership tier needs no changes to existing code. ...

Mastering owned entities in EF Core: Cleaner complex types

Uses a PostgreSQL-backed EF Core console app with a Movie entity and a Budget owned entity holding ProductionCost, MarketingCost, and DistributionCost to show how owned types get stored as prefixed columns in the parent table without their own primary key, DbSet, or independent lifecycle. ...

Building Read Models with EF Core Projections

Compares fetching a PostgreSQL Movie/Director schema with and without EF Core projections, showing how loading full entities with every column and navigation property triggers extra change tracking, slower deserialization, and N+1 query risk versus selecting only the fields a view actually needs. ...

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

Builds the same Product/Quantity/Price Excel report three ways in C# with the low-level DocumentFormat.OpenXml SDK's SpreadsheetDocument and WorkbookPart classes, then EPPlus, then ClosedXML, contrasting OpenXML's verbose cell-by-cell XML construction against the other libraries' higher-level APIs. ...

Repository pattern vs Specification: Which is more maintainable?

Compares DDD's Repository pattern against the Specification pattern using a Building aggregate root with nested Floor and Location child entities, showing how encapsulating query logic in reusable Specification objects scales better than adding new repository methods each time query needs grow. ...

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

Explains the .NET Garbage Collector's mark, relocate, and compact phases on the managed heap and its Gen 0/1/2 generational model, showing why short-lived objects like loop variables are reclaimed cheaply in Gen 0 while longer-lived objects get promoted to slower, less frequent collections. ...

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

Uses BenchmarkDotNet with MemoryDiagnoser to measure boxing a plain int into object, unboxing it back, and comparing both against an unboxed baseline, then extends the test to ArrayList versus List<int> to quantify how boxing's hidden heap allocations and GC pressure outweigh simple stack usage. ...