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

Schedule Background Job using Quartz.NET

Implements Quartz.NET scheduling two ways: a console PrintJob firing every 5 seconds via IJob, StdSchedulerFactory, and WithSimpleSchedule().RepeatForever(), then an ASP.NET Core alarm job configured through appsettings.json using the Cron expression 0 0 7 * * ? to run automatically at 7 AM daily. ...

Exploring C# Records and Their Use Cases

Contrasts C# 9.0 records against classes using a Student(Name, Age) example: records give value-based equality, so two identical Students compare equal, versus classes' reference equality, plus the with expression for non-destructive copies, then argues for records as concise, immutable API DTOs. ...

What's new in .NET 9: System.Text.Json improvements

Walks through .NET 9's JsonSchemaExporter in System.Text.Json: calling GetJsonSchemaAsNode on a Student record to produce a JSON Schema document, then customizing output via JsonSerializerOptions with SnakeCaseLower naming, NumberHandling.WriteAsString, and JsonUnmappedMemberHandling.Disallow. ...