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.

67 posts
Understanding EF Core Change Tracking: How It Works Under the Hood

Traces what EF Core's ChangeTracker does with a Student/Enrollment model: context.Add marks new entities Added and assigns temporary keys, SaveChanges emits INSERTs in dependency order and backfills the real StudentId foreign key, versus attaching an Enrollment to an already-tracked Student. ...

.NET Dependency Injection: Advanced Techniques Beyond the Basics

Goes beyond Singleton/Scoped/Transient basics with concrete .NET DI patterns: resolving services manually in an MqttListener via IServiceProvider versus IServiceScopeFactory for scoped lifetimes, injecting IEnumerable to get every registered implementation, and registering variants via AddKeyed. ...

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