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.

71 posts •
Why IEnumerable Can Kill Performance in Hot Paths

Benchmarks IEnumerable against List, arrays, LINQ chains, and yield-based sequences in C# using BenchmarkDotNet with collection sizes of 1,000 and 100,000, showing how deferred execution and repeated enumeration can make IEnumerable up to 7x slower than a materialized List in hot paths. ...

Polymorphic Relationships in EF Core: Three Approaches

Compares EF Core's Table-per-Hierarchy, Table-per-Type, and Table-per-Concrete-Type inheritance strategies using an abstract Employee base class with Contractor, FullTimeEmployee, and PartTimeEmployee subtypes, configuring TPH with HasDiscriminator<EmployeeTypeEnum> to store every row in one table. ...

Implementing strongly-typed IDs in .NET for safer domain models

Uses a PostgreSQL-backed EF Core project with Player, Team, and PlayerTeam entities to show how primitive obsession with plain int IDs lets a TeamId slip in where a PlayerId is expected, then wraps each ID in a strongly-typed struct so mixing them up becomes a compile-time error. ...

New in .NET 10 and C# 14: Multi-Tenant Rate Limiting

Builds a multi-tenant rate limiter in a .NET 10 LTS Web API using the native RateLimitPartition.GetTokenBucketLimiter, a TenantResolver that reads the X-Tenant-ID header, and per-tenant token bucket policies returning 429 Too Many Requests once a tenant's plan-based request limit is exceeded. ...

New in .NET 10 and C# 14: Fast Model Validation for APIs

Benchmarks a CreateDeviceRequest DTO validated with DataAnnotations like Required and Range across identical .NET 8 and .NET 10 Web APIs using BenchmarkDotNet and HttpClient, showing how .NET 10's reflection-free validation metadata cuts request latency by roughly 3x on invalid payloads. ...

New in .NET 10 and C# 14: Enhancements in APIs Request/Response Pipeline

Compares a .NET 8 minimal API against a .NET 10 minimal API using BenchmarkDotNet, showing how static lambda route handlers eliminate closure allocations and how AllowOutOfOrderMetadataProperties speeds up JSON deserialization to cut a /weather endpoint's response time and GC pressure. ...

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