Dear Santa: One Table, Three Shapes of Data in EF Core 10

This post is my entry for C# Advent 2026. Two new C# posts open every day through December 25, so go see what’s behind the other doors once you’re done here.
It’s December at the North Pole and the mailroom is buried. Somewhere near the top of the pile is this one:
Dear Santa, I want something to build spaceships with. My sister says socks are fine. I have been mostly good this year. I will leave cookies.
That’s Timmy. He’s seven, and his letter is a data modeling problem.
The envelope is easy. Name, age, region, naughty or nice: those are columns, and the elves have been filtering on them for centuries. The letter is harder. Timmy sent two wishes, his neighbor sent one, and a kid in the Alps sent a wish plus an apology about a snowman. Nothing about that wants to be a fixed set of columns. And then there’s what Timmy meant. Nobody at the workshop makes a product called “something to build spaceships with.”
A few years ago the elves would have stood up three systems for this: SQL Server for the envelope, a document database for the letter, and a vector database for the meaning. Then they’d have spent every December keeping the three in sync.
This year they did it in one table. EF Core 10 and SQL Server 2025 can put relational columns, a native json column, and a vector column side by side, and query all three with LINQ. This post walks through each shape with a small solution you can run. Every SQL statement and every number below came from running it.
The workshop
The solution has 46 toys and 22 letters. Here’s the entity that matters:
public class Letter
{
public int Id { get; set; }
public int ChildId { get; set; }
public Child Child { get; set; } = null!;
public int Year { get; set; }
public DateOnly ReceivedOn { get; set; }
public required string Body { get; set; } // the letter as written
public required WishList WishList { get; set; } // one json column
public SqlVector<float> Embedding { get; set; } // one vector(384) column
}
One row, three shapes.
The envelope
I’ll be quick here, because there’s nothing new. Child has Name, Age, Region, and IsNice, and they’re ordinary columns with an ordinary index:
var kids = await db.Children
.Where(c => c.Region == region && c.IsNice)
.OrderBy(c => c.Name)
.Select(c => new { c.Name, c.Age })
.ToListAsync();
The reason this section exists at all is to say what stays out of the JSON. If you filter on it, join on it, or sort on it every day, it’s a column. Santa asks “who’s nice in the Great Lakes region” far too often for that answer to live inside a document.
The letter
The wish list is a complex type. It has no key and no identity of its own; it’s a value that belongs to the letter.
public class WishList
{
public required string TopWish { get; set; }
public bool CookiesPromised { get; set; }
public string? NoteToSanta { get; set; }
public List<Wish> Wishes { get; set; } = [];
}
public class Wish
{
public required string Item { get; set; }
public int Priority { get; set; }
public string? Color { get; set; }
}
Mapping it takes one line:
letter.ComplexProperty(l => l.WishList, wishList => wishList.ToJson());
That List<Wish> is why this is JSON. A complex type mapped the default way (table splitting) gets a column per property, and a list has nowhere to go. A document doesn’t care how many wishes a kid has.
The setting that’s easy to miss
Leave out one setting and the migration creates this column as nvarchar(max). On SQL Server 2025. With the native json type sitting right there.
EF Core 10 doesn’t ask the server what it supports. It assumes a compatibility level, and unless you say otherwise that level predates the json type. I checked three settings against the same model: the default gave me nvarchar(max), so did 160, and only 170 produced json.
options.UseSqlServer(connectionString, sql => sql.UseCompatibilityLevel(170));
With that in place the migration says type: "json". One warning if you’re adding this to an existing app: Microsoft’s docs say the next migration will convert your existing nvarchar JSON columns to json. Read that migration before you run it.
Querying inside the document
Who promised cookies? (Santa keeps track.)
var cookieKids = await db.Letters
.Where(l => l.WishList.CookiesPromised)
.OrderBy(l => l.Child.Name)
.Select(l => new { l.Child.Name, l.WishList.TopWish })
.ToListAsync();
SELECT [c].[Name], JSON_VALUE([l].[WishList], '$.TopWish' RETURNING nvarchar(max)) AS [TopWish]
FROM [Letters] AS [l]
INNER JOIN [Children] AS [c] ON [l].[ChildId] = [c].[Id]
WHERE JSON_VALUE([l].[WishList], '$.CookiesPromised' RETURNING bit) = CAST(1 AS bit)
ORDER BY [c].[Name]
Look at RETURNING bit. Older versions of JSON_VALUE only gave you back a string, and EF had to wrap it in a cast. Now the server hands back the type you asked for. Ten of the 22 kids promised cookies, including one of the two on the naughty list, which I respect as a strategy.
Reaching into the collection works too. Who asked for something red?
.Where(l => l.WishList.Wishes.Any(w => w.Color == "red"))
WHERE EXISTS (
SELECT 1
FROM OPENJSON([l].[WishList], '$.Wishes') WITH ([Color] nvarchar(max) '$.Color') AS [w]
WHERE [w].[Color] = N'red')
Three kids did: a fire truck, a leash, and “something loud to hit.”
The kid changes their mind
Kids revise. Emma, who is seven and paints sunsets, sends a postcard: P.S. I will leave cookies after all.
That’s one property in one document, and I don’t want to load the letter, change a bool, and send the whole thing back. ExecuteUpdateAsync can reach inside the JSON in EF Core 10:
await db.Letters
.Where(l => l.Id == emma.Id)
.ExecuteUpdateAsync(s => s.SetProperty(l => l.WishList.CookiesPromised, true));
UPDATE [l]
SET [WishList].modify('$.CookiesPromised', @p)
FROM [Letters] AS [l]
WHERE [l].[Id] = @emma_Id
.modify() is the new method on the json type, and it patches one path. This only works because WishList is a complex type. Owned entities mapped to JSON don’t get it, which is the practical reason I chose complex types back in the last section.
Then a second letter arrives. Emma is done with paints. She wants to make bowls out of clay, on a wheel, like the lady at the market. That changes the body of the letter, two properties in the wish list, and the meaning. So all three shapes have to move, and they can move in one statement:
await db.Letters
.Where(l => l.Id == emma.Id)
.ExecuteUpdateAsync(s => s
.SetProperty(l => l.Body, SeedData.EmmaSecondLetter)
.SetProperty(l => l.WishList.TopWish, SeedData.EmmaSecondTopWish)
.SetProperty(l => l.WishList.NoteToSanta, "Changed her mind. Forget the paints.")
.SetProperty(l => l.Embedding, newVector));
UPDATE [l]
SET [l].[Body] = @p,
[l].[WishList] = JSON_MODIFY(JSON_MODIFY([l].[WishList], '$.TopWish', @p2), '$.NoteToSanta', @p3),
[l].[Embedding] = @p4
FROM [Letters] AS [l]
WHERE [l].[Id] = @emma_Id
Here’s something I didn’t expect. Set one property and you get .modify(). Set two properties in the same document and EF switches to nested JSON_MODIFY calls that assign the whole column. Both work, and I haven’t measured the difference on a big document, but if you were counting on the in-place patch, look at your SQL.
For comparison, the demo also does it the tracked way: load the letter, add a wish to the list, call SaveChanges. That sends UPDATE [Letters] SET [WishList] = @p0, the entire document. Fine for a letter to Santa. Less fine for a 2 MB document you touch a thousand times a minute.
Before the update, Emma’s best match was the Watercolor Studio Set. After it, the Clay Creations Pottery Wheel. It took one round trip, and because it was one statement, the column, the document, and the vector were never out of step with each other.
What the kid meant
Now the fun part. Toys and letters both get a vector column:
toy.Property(t => t.Embedding).HasColumnType("vector(384)");
The 384 belongs to the embedding model, not to SQL Server. I used all-minilm through Ollama because it’s free and small enough to run on a laptop. The vectors for the seed data ship in the repo, so you don’t need Ollama (or an API key) to run any of this.
My first try sent Timmy socks
I did the obvious thing first. I embedded each letter whole and asked for the nearest toy that fit the kid’s age.
| Letter | Nearest toy |
|---|---|
| “…something to build spaceships with. My sister says socks are fine…” | Cozy Striped Wool Socks |
| “…score goals like my hero and practice in the yard every day…” | Backyard Bug Explorer Kit |
| “…I bang on pots and pans every day, and Mama says please ask Santa for something else to hit…” | Tiny Chef Play Kitchen |
Timmy’s sister won. The soccer kid got a bug net, presumably because he said “yard.” And Lars, whose mother is begging for relief from the pots and pans, was matched with a toy kitchen. With pots.
The model did its job. An embedding of a whole letter is an average of everything in it, and a kid’s letter is mostly cookies and character references. The wish is a minority of the words.
The fix was already sitting in the JSON column. The mailroom elves pull a TopWish out of each letter, so I embedded that and nothing else.
Second try
var toys = await db.Toys
.Select(t => new
{
t.Name,
t.Description,
Distance = EF.Functions.VectorDistance("cosine", t.Embedding, letter.Embedding)
})
.OrderBy(t => t.Distance)
.Take(5)
.ToListAsync();
SELECT TOP(@p) [t].[Name], [t].[Description], VECTOR_DISTANCE('cosine', [t].[Embedding], @letter_Embedding) AS [Distance]
FROM [Toys] AS [t]
ORDER BY VECTOR_DISTANCE('cosine', [t].[Embedding], @letter_Embedding)
For “Something to build spaceships with”:
| Distance | Toy |
|---|---|
| 0.514 | Star Hauler Brick Set: 620 snap-together bricks for making rockets, shuttles and a launch tower. |
| 0.567 | Junior Rocket Blocks |
| 0.621 | Moon Base Mega Bricks |
| 0.630 | Coastline Wooden Train Set |
| 0.675 | Backyard Bug Explorer Kit |
Read the winner again. It doesn’t contain “build” or “spaceship.” A LIKE query finds nothing here, and I wouldn’t bet on full-text search either. The top three are all space-themed building sets. After that the model starts guessing, which is what a distance of 0.63 is telling you.
Santa doesn’t hand a four-year-old real glassware
Priya is four and wants “a potion-making science kit.” By meaning alone, her top two are the Fizzy Potion Kitchen (ages 4 to 8) at 0.380 and the Bubbling Beaker Chemistry Lab (ages 10 to 16) at 0.414. That second one comes with real glassware and experiments that smoke. It’s a close second.
The vector knows what things mean. It has no idea how old anyone is or what’s on the shelf. Those are relational facts, and this is where one table pays off:
var suitable = await db.Toys
.Where(t => t.InStock > 0 && t.MinAge <= letter.Age && t.MaxAge >= letter.Age)
.Select(t => new
{
t.Name, t.MinAge, t.MaxAge,
Distance = EF.Functions.VectorDistance("cosine", t.Embedding, letter.Embedding)
})
.OrderBy(t => t.Distance)
.Take(3)
.ToListAsync();
SELECT TOP(@p) [t].[Name], [t].[MinAge], [t].[MaxAge], VECTOR_DISTANCE('cosine', [t].[Embedding], @letter_Embedding) AS [Distance]
FROM [Toys] AS [t]
WHERE [t].[InStock] > 0 AND [t].[MinAge] <= @letter_Age AND [t].[MaxAge] >= @letter_Age
ORDER BY VECTOR_DISTANCE('cosine', [t].[Embedding], @letter_Embedding)
A WHERE clause and a vector ranking in the same statement, against the same rows, in the same transaction. With a separate vector database, that’s two calls and some glue code that decides what to do when the nearest five toys are all out of stock.
The whole list in one query
And here is the query the post has been building to. Every nice kid, the top wish from their JSON, and the best toy that’s in stock and fits their age:
var list = await db.Letters
.Where(l => l.Child.IsNice)
.OrderBy(l => l.Child.Name)
.Select(l => new
{
l.Child.Name,
l.Child.Age,
l.WishList.TopWish,
Gift = db.Toys
.Where(t => t.InStock > 0 && t.MinAge <= l.Child.Age && t.MaxAge >= l.Child.Age)
.OrderBy(t => EF.Functions.VectorDistance("cosine", t.Embedding, l.Embedding))
.Select(t => t.Name)
.First()
})
.ToListAsync();
SELECT [c].[Name], [c].[Age], JSON_VALUE([l].[WishList], '$.TopWish' RETURNING nvarchar(max)) AS [TopWish], (
SELECT TOP(1) [t].[Name]
FROM [Toys] AS [t]
WHERE [t].[InStock] > 0 AND [t].[MinAge] <= [c].[Age] AND [t].[MaxAge] >= [c].[Age]
ORDER BY VECTOR_DISTANCE('cosine', [t].[Embedding], [l].[Embedding])) AS [Gift]
FROM [Letters] AS [l]
INNER JOIN [Children] AS [c] ON [l].[ChildId] = [c].[Id]
WHERE [c].[IsNice] = CAST(1 AS bit)
ORDER BY [c].[Name]
A join, a JSON path, and a vector distance between two columns. No parameters at all, because the letter’s vector never leaves the server. A few rows from the result:
| Kid | Age | Top wish | Gift |
|---|---|---|---|
| Aiko Tanaka | 8 | Something for looking at Saturn and the moon | Starlight Telescope |
| Ethan Clarke | 12 | A way to send secret messages across the street | Over-and-Out Walkie Talkies |
| Lars Eriksson | 6 | Something loud to bang on | Tabletop Bongo Pair |
| Mateo Alvarez | 9 | A dog that does not shed or need walks | Robo-Pup Companion |
| Mia Hernandez | 5 | Something to make bedtime less dark | Starry Night Projector |
| Timmy Novak | 7 | Something to build spaceships with | Star Hauler Brick Set |
I’d sign off on all 20. Lars got bongos when there was a full drum kit in the catalog, and I suspect his mother would call that a win.
Christmas Eve
Forty-six toys is a demo. The real warehouse is bigger, so I filled a table with random vectors and ran Timmy’s letter against it. Same three questions I ask of any query: what did EF send, what did the optimizer see, and who owns the fix?
EF sent this:
-- act5:nearest-warehouse-items
SELECT TOP(@p) [w].[Sku]
FROM [WarehouseItems] AS [w]
ORDER BY VECTOR_DISTANCE('cosine', [w].[Embedding], @timmy)
The optimizer saw a sort it had no shortcut for:
Top
Parallelism (Gather Streams)
Sort
Compute Scalar, estimated rows 50,000
Clustered Index Scan, estimated rows 50,000
Scan every row, compute a distance for every row, sort, keep five. And it costs what you’d guess:
| Warehouse items | Median time | Logical reads |
|---|---|---|
| 50,000 | 31 ms | 10,543 |
| 500,000 | 313 ms | 105,460 |
Ten times the rows, ten times the reads, ten times the wait. VectorDistance in EF Core 10 is an exact search, and exact means it looks at everything. Each vector(384) value is 1,544 bytes, so the 500,000-row table came to 800 MB before a single index. (Those timings are from a 2-vCPU container. Yours will differ; the shape won’t.)
Who owns the fix? In EF Core 10, mostly you, and your best tool is the WHERE clause from the last section. Every toy the relational filter removes is a distance the server never computes.
What EF Core 11 adds
EF Core 11 shipped with .NET 11 on November 10, and it’s the first version that can ask for an approximate search. I haven’t moved this repo to it, so this snippet is from Microsoft’s docs and not from my own run:
modelBuilder.Entity<WarehouseItem>()
.HasVectorIndex(i => i.Embedding, "cosine");
var items = await db.WarehouseItems
.VectorSearch(i => i.Embedding, timmy, "cosine")
.OrderBy(r => r.Distance)
.Take(5)
.WithApproximate()
.ToListAsync();
Microsoft marks both the EF API and the SQL Server feature underneath it as experimental. I wanted to know what that means in practice, so I built the index by hand in T-SQL on the 50,000-row table (the script is in the repo). Four things happened:
- It needs
PREVIEW_FEATURES = ONat the database level. - The build took about five minutes for 50,000 rows.
- The search was quick: 3 ms against 19 ms for the exact query in the same session.
- While the index existed, the table was read-only. Every
INSERTandDELETEfailed with Msg 42231, “Data modification statement failed because table ‘WarehouseItems’ has a vector index on it.”
Number four is the one to sit with. On my build (SQL Server 2025 CU11), a vector index and Emma’s change of heart can’t live on the same table. I also got five completely different items back from the approximate search than from the exact one. Random vectors are the worst case for that, since everything is about equally far from everything else, but it’s a good reminder of what “approximate” means.
One more EF Core 11 change is worth knowing now. When EF Core 10 loads a Letter entity, the SELECT includes [l].[Embedding], all 1,544 bytes of it, whether you wanted it or not. EF Core 11 stops doing that. Until you upgrade, project the columns you need and leave the vector on the server.
Where the sleigh stops
A few limits before you put this in production.
If you never query inside the document, you don’t need the json type. Store the text and move on.
Exact search has a ceiling, and you saw the slope. Tens of thousands of rows behind a good WHERE clause is comfortable. Millions of rows with no filter is a different project, and today that project comes with a read-only table.
Embeddings belong to a model. Switch from all-minilm to something bigger and the 384 changes, which means a migration and re-embedding every row. Keep the source text. I keep Body and TopWish right next to the vector for exactly that reason.
And the lesson that cost Timmy his spaceship, briefly: what you embed matters more than which model you pick. The best thing I did for search quality in this whole project was a decision about a JSON property.
Run it yourself
The solution is two projects: NorthPole.Data (entities, the context, one migration, seed data) and NorthPole.Workshop (a console app with one file per section of this post). You need the .NET 10 SDK and SQL Server 2025 in a container.
dotnet run --project src/NorthPole.Workshop
It creates its own NorthPole database, loads the toys and the letters, and prints the real SQL for every query above. It’s in github.com/cwoodruff/EFCoreDemos, in the LettersToSanta folder. If you have Ollama running, you can send your own wish:
dotnet run --project src/NorthPole.Workshop -- ask "something to catch fish with at the lake" --age 8
That one comes back with the Tackle Box Starter Rod.
So that’s the North Pole’s architecture this year: one table holding three shapes of data, and no new servers to babysit. The elves got their December back.
If you try it, tell me which of your letters got the funniest wrong answer. I’m woodruff.dev on Bluesky and chriswoodruff on LinkedIn. Merry Christmas, and may your sister’s suggestions stay in the JSON where they belong.


