The Problem Worth Solving
You have a Product entity with fifteen optional specification fields. Half of them are null for most rows. Adding a new field means a migration. Querying by any combination of them means either a bloated WHERE clause or an EAV table that turns into a JOIN nightmare. PostgreSQL's jsonb column exists for exactly this case, and EF Core 10 with Npgsql.EntityFrameworkCore.PostgreSQL 10 maps it as a real part of the model.
This article covers the mapping, what LINQ translates to, which indexes the planner actually uses, and when a jsonb column beats a separate table. Every snippet here was run against PostgreSQL 18 with Npgsql.EntityFrameworkCore.PostgreSQL 10.0.3, and a few things that look obvious turned out not to work. Those are called out where they come up.
Mapping: Complex Types with ToJson()
In EF Core 10 the recommended approach is to map a .NET complex type to a jsonb column with ComplexProperty(...).ToJson() .…