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
Simplifying file logging in ASP.NET Core with Serilog

Add file logging to an ASP.NET Core API with Serilog: configure the File sink, enable daily rolling logs, move settings to appsettings.json, control log levels, and enrich entries with machine name and user context. Includes a startup-exception logging example and production tips. ...

EF Core at scale: 5 ways to retrieve large datasets efficiently

Five EF Core bulk-fetch methods from Z.EntityFramework.Extensions that bypass the 2,100-parameter limit of .Contains: WhereBulkContains, WhereBulkNotContains, BulkRead, WhereBulkContainsFilterList, and WhereBulkNotContainsFilterList, benchmarked on a 1M-row PostgreSQL dataset. ...

Designing high-throughput APIs for 1M requests/minute .NET

Builds an ASP.NET Core Minimal API benchmarked with BenchmarkDotNet against a PostgreSQL Orders table, comparing a naive EF Core query using Include and Take(50000) against a raw Dapper query with pagination, indexing, and connection pooling to sustain 1M requests per minute. ...

How to upload files in an ASP.NET Core Web API

Shows how to build a file upload endpoint in a .NET 10 ASP.NET Core Web API using IFormFile and FileStream, add Swashbuckle.AspNetCore for OpenAPI/Swagger docs, cap uploads at 100 MB via MultipartBodyLengthLimit, and organize the code into clean, testable service layers with download support. ...

The complete guide to mastering Dapper micro-ORM in .NET

Walks through building a .NET console app that uses Dapper, the micro-ORM created by Stack Overflow, with Npgsql to query a PostgreSQL database of Movie and Director records, covering a DbConnectionFactory setup, JOINs, aggregate functions, stored procedures, and transactions. ...

Pattern matching in C#: Advanced scenarios you didn't know

Demonstrates advanced C# pattern matching using record types for User, Address, and Request, covering nested property patterns like user is { Address.City: "Karachi" }, negation with 'not', combined 'or' cases, LINQ filtering by shape, and relational patterns like age is > 18 and < 60. ...

12 practices for optimizing PostgreSQL queries for large datasets

Covers 12 PostgreSQL tuning techniques with EXPLAIN ANALYZE benchmarks, including adding a customer_id index that cuts a 240ms query, avoiding SELECT *, reordering JOINs so the smaller table filters first, using LIMIT, partial indexes like idx_completed_orders, and choosing efficient data types. ...

EF Core query translation: Why does some LINQ never become SQL?

Explains why some EF Core LINQ queries fail to translate to SQL, using a Perfume model backed by PostgreSQL and Npgsql to show ToQueryString() output, how StartsWith becomes a SQL LIKE clause, and cases involving custom methods or reflection that force client-side evaluation instead. ...

Mapping database views in EF Core without breaking migrations

Shows how to map a read-only PostgreSQL view named vw_product_summary into a ProductSummary entity in EF Core using ToView() and HasNoKey(), keeping the mapped view separate from the Product table so schema migrations don't break when the view definition changes. ...