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
Handling Complex Query Scenarios with Entity Framework Core

Speeds up EF Core queries on a Building/Floor model: projecting only needed columns into a DTO, disabling tracking per-query with AsNoTracking or globally via HasQueryTrackingBehavior, choosing lazy loading with Microsoft.EntityFrameworkCore.Proxies versus eager loading, plus indexing/pagination. ...

Leveraging Tuples in C#: Real-World Use Cases

Shows C# tuple syntax from Tuple<T> through named literal tuples (C# 7.0+), nested tuples, and deconstruction, then two real examples: passing a (Latitude, Longitude) tuple as a method parameter, and returning a (Subject, Body) tuple from an email-content generator keyed off an EmailTypeEnum. ...

Unlocking delegate's potential in C#

Builds C# delegate intuition with a waiter/chef analogy, then two code examples: a multicast PrintMessage delegate chaining PrintToConsole and PrintToFile via +=, and a menu-driven console app mapping user choices to AddContact/ViewContact/DeleteContact through a Dictionary<string, PrintMessage>. ...

Understanding Complex Types in Entity Framework: A Complete Guide

Demonstrates EF Core's complex type feature via a shared ContactInfo record (PhoneNumber, Email) reused across Customer, Employee, and Vendor entities, showing how EF Core flattens it into ContactInfo_PhoneNumber/ContactInfo_Email columns per table, then wiring it up with the Owned annotation. ...

Comparing Records, Structs, and Classes in C#: When to Use What?

Compares C# type declarations with side-by-side examples: a mutable Student class where s2 = s1 shares one reference so changing s2.Semester also changes s1.Semester, a Point struct where copies behave as independent value types, and C# 9.0's immutable records with built-in equality and hashing. ...

How to create custom controls in .NET MAUI

Builds a reusable GradientButton control in .NET MAUI step by step: scaffolding a ContentView in a controls folder under MVVM, swapping its default Label for a named Button, then exposing a bindable Text property via BindableProperty.Create so it binds from XAML like any built-in control. ...

How to Monitor Your App's Performance with .NET Benchmarking

Introduces BenchmarkDotNet for .NET performance testing: marking a SumNumbers method with [Benchmark], running it via BenchmarkRunner.Run in Release configuration, understanding its warmup and pilot-run process for JIT-optimized results, and parameterizing input sizes with [Params(10, 100, 1000)]. ...

How to bulk insert with EF Core

Compares four ways to bulk insert an Order entity in EF Core: naive per-record Add plus SaveChangesAsync, DbSet.AddRangeAsync, the EFCore.BulkExtensions package's BulkInsertAsync for true batched inserts, and raw SQL, weighing each against change-tracker overhead and round-trip cost at scale. ...

C# 13 Features: What's New and How to Use It

Covers C# 13 on .NET 9: extending params beyond arrays to Span<T>, stack-allocated ReadOnlySpan<T>, and IEnumerable<T> collections, plus the new implicit index operator, a dedicated escape sequence, the System.Threading.Lock type, and optimized overload resolution, each with runnable code. ...