From 5a7d287e19d2bdabcab207700a47409561a2b116 Mon Sep 17 00:00:00 2001 From: electricessence <5899455+electricessence@users.noreply.github.com> Date: Tue, 1 Dec 2026 07:49:53 -0800 Subject: [PATCH 1/2] Deck: rebuild the presentation picture-first Rebuild docsite/presentation/index.html to the communication-design plan: 16 main slides in the order easy, fast, calm under load, light and correct, close. Pictures come before words; code appears on three slides only (the five-line call, the one-word opt-in, the install line). - New anchor picture of one call (open, run, read, close) and the two-lane default against opt-in timeline, with a calm and a busy server. - The 22 lines of plain ADO.NET are drawn as bars; the code moves to the appendix. - Generator slide: annotated models equal hand-written; an unannotated model pays one small column-name check per query (about 1 ns per column), and annotating skips it. - Real-database chart: the grey part is plain ADO.NET building the same objects; each method shows its extra on top. Held-time chart is worded "time per call". Dapper.AOT is stated honestly: generated is ahead on mapping, level on a real database, within noise. - Every existing data-pending slot id is kept; no number is filled in. - Detail slides move to an appendix reached from the Go deeper map; two small appendix slides are new (generator details, SQLite and memory). Co-Authored-By: Claude Opus 5.5 --- docsite/presentation/index.html | 1614 ++++++++++++++++++++----------- 1 file changed, 1069 insertions(+), 545 deletions(-) diff --git a/docsite/presentation/index.html b/docsite/presentation/index.html index cda2ba7c..c8eec70a 100644 --- a/docsite/presentation/index.html +++ b/docsite/presentation/index.html @@ -4,7 +4,7 @@ ODX v11: a presentation for developers - + + +
-
Version 11.0

Open.Database.Extensions
(ODX) v11

-

You write the SQL.
ODX writes the other twenty lines.

-

Extensions on the ADO.NET types you already use. Any provider. MIT.

+

You write the SQL.
ODX writes everything around it.

+

Sixteen pictures. Details at the end.

open-net-libraries.github.io/Open.Database.Extensions

-

The problem

-

One author's posts, with plain ADO.NET: 22 lines.

+

Most database code is plumbing, not the query.

-
- -
var posts = new List<Post>();
-await using var connection = new SqliteConnection(connectionString);
-await connection.OpenAsync(cancellationToken);
-await using var command = connection.CreateCommand();
-command.CommandText =
-    "select id, author, title, body from posts "
-    + "where author = @author order by id";
-var parameter = command.CreateParameter();
-parameter.ParameterName = "@author";
-parameter.Value = author;
-command.Parameters.Add(parameter);
-await using var reader = await command.ExecuteReaderAsync(cancellationToken);
-while (await reader.ReadAsync(cancellationToken))
-{
-    posts.Add(new Post
-    {
-        Id = reader.GetInt32(0),
-        Author = reader.GetInt32(1),
-        Title = reader.GetString(2),
-        Body = reader.IsDBNull(3) ? null : reader.GetString(3),
-    });
-}
-
← the part you meant to write
+
+ + + + + + the part you + meant to write + +
-
+
Connection Command Parameter Read loop Column copying Disposal + The SQL
-

ODX in one call

-

You keep your SQL. ODX does the rest.

-
int author = 42;
-
-Post[] posts = await connectionFactory
+  

The plumbing goes away. The SQL stays.

+
+
+ + +
+
+
+

Lines you write

+
Plain ADO.NET
22
+
ODX
5
+
+
+
+
Post[] posts = await connectionFactory
     .Command("select * from posts where author = @author order by id")
-    .AddParam(author) // name and type inferred from the variable
+    .AddParam(author)
     .Map<Post>()
     .ToArrayAsync(cancellationToken);
-
-
-

Not written by you

-
- ✓ Connection - ✓ Command - ✓ Parameter - ✓ Read loop - ✓ Column copying - ✓ Disposal +
-
-

Lines you write

-
ADO.NET
22
-
ODX
5
-
-

connectionFactory is created once per application.

-
-

Setup once, code per call

-

An ORM looks like less code because the setup is written somewhere else.

-
-
-

ODX: not an ORM. Define once, you write the SQL

-
static readonly MappedDbQuery<Post> AllPosts
-    = DbQuery.Text(AllPostsSql).Map<Post>();
-
-// per call
-=> AllPosts.Using(connectionFactory)
-    .ToListAsync(cancellationToken);
-
-
-

EF Core: an ORM with change tracking and SaveChanges.
A context first, then LINQ

-
// per call
-=> db.Posts.OrderBy(static p => p.Id)
-    .ToListAsync(ct);
-
-
-
-

Lines you write for task 1, rows to a list: once, and per call

-
onceper call
- -
ODX
7 per call, 1–3 once
-
EF Core
6 per call, 5 once+ configuration, registration: not counted
-
Dapper
9 per call, no setup
-
ADO.NET
22 per call, no setup
+

Where it sits

+

The SQL-first choice that costs nothing at run time.

+
+
you write everythingthe library writes the SQL
+
+
ADO.NETDapperODXEF Core
+
You write the SQL✓✓✓—
+
Lines per call22976
+
Tracks changes, saves for you———✓
-

Dapper and ADO.NET create the connection in every call.

-
-

Hand-written is the ceiling

-

A reader written by hand has nothing to work out at run time.

-
-
-
Once per result set
match column names, check the layout→fixed ordinals
-
Per row
work out the shape→plain loop
-
Per cell
look up, box, convert→GetInt32(0)
-

It is also code you write and keep in step with every query by hand.

-
-
- -
[rc.16]µs
-

Hand-written selector.
Connection held open, 20 columns,
1,000 rows, synthetic reader.

- -
+

One call, start to finish

+

Four stages. ODX owns all of them.

+
+ + + connections + + + ODX + + opentake a connectionrun the querythe database worksrows come backin burstsclosegive it back + + connection in use + + + your code + + + + Remember the orange bar. The rest of the deck makes it short and the middle cheap. +
- -
-

ODX generates that code for you

-

So plain .Map<T>() reaches the ceiling. Nothing to write.

- +
+

The code you would have written by hand

+

The fastest reader is written for one query. ODX writes it when you build.

+ The source generator writes a reader from your model and hands it to the same Map(selector) path as a hand-written selector. Post (your model) @@ -731,328 +868,248 @@

ODX generates that code for you

rows - - - Generic method: runtime map, - compiled once per shape, cached - -
Opt out: <OdxGenerateMaps>false</OdxGenerateMaps>C# 12 or later
+

Nothing to look up while it runs.

+
Annotated model: the same as hand-written.No annotations: one small check of column names per query, about 1 ns per column. Annotate, and it is skipped.
-
-

Against Dapper and Dapper.AOT

-

Same query, same rows. 20 columns, 1,000 rows, synthetic reader (no database).

-
-
-

Connection held open (shorter is better)

-
- -
Hand-written selector[rc.16]
- -
ODX Map<T>()[rc.16]
- -
Dapper.AOT[rc.16]
- -
Dapper Query<T>[rc.16]
-
-

Memory allocated

-
- -
ODX, selector, AOT[rc.16]
- -
Dapper Query<T>[rc.16]
+

How fast

+

Time per call to read 1,000 rows of 20 columns. No database in the way. Shorter is better.

+
+
+
+
Hand-written[pending]
+
ODX Map<T>()[pending]
+
Dapper.AOT[pending]
+
Dapper[pending]
-
-
- -
[rc.16]×less connection time
than Dapper
-
[rc.16]×less memory
than Dapper
-
-
-

Real databases, 10,000 rows of 20 columns.
Grey: a plain loop reading every value. On top: each library.

- -
-

SQL Server LocalDB plain loop: [rc.16] ms

-
ODX Map<T>()+[rc.16] ms
-
Hand-written+[rc.16] ms
-
Dapper.AOT+[rc.16] ms
-
Dapper+[rc.16] ms
-
-
-

SQLite file plain loop: [rc.16] ms

-
ODX Map<T>()+[rc.16] ms
-
Hand-written+[rc.16] ms
-
Dapper.AOT+[rc.16] ms
-
Dapper+[rc.16] ms
-
- -

Memory: Dapper allocates [rc.16] more than ODX on SQL Server, [rc.16] more on SQLite.

+
+
+
[pending]×less time per call
than Dapper
+
[pending]×less memory
than Dapper
+

Level with hand-written. Ahead of Dapper.AOT and Dapper on mapping.

-
-

Define once, bind where it runs

-

A query is a value: immutable, no connection, safe in a static field.

-
// Recommended.
-static readonly MappedDbQuery<Post> ByAuthor
-    = DbQuery.Text(ListSql).Map<Post>();
-
-public ValueTask<List<Post>> ByAuthorAsync(
-    int author,
-    CancellationToken cancellationToken)
-    => ByAuthor.Using(connectionFactory)
-        .AddParam(author)
-        .ToListAsync(cancellationToken);
-

One-row call at 20 columns, µs, runtime map. Shorter is better.

-
Map cached, reused
-
0.28 about 3,100 times
-
New RowMap<T> at the call site
-
870
-

Building the map: 190 to 870 µs for 1 to 20 columns.
With the generator, at build time, except in a generic method.

+

On a real database

+

SQL Server LocalDB. 10,000 rows of 20 columns. Time per call.

+
The database itself: plain ADO.NET building the same objects, [pending] msEach method's extra time on top
+
+
ODX Map<T>()
+[pending] ms
+
Hand-written
+[pending] ms
+
Dapper.AOT
+[pending] ms
+
Dapper
+[pending] ms
+
+
+

ODX, hand-written and Dapper.AOT: level, within noise.

+

Memory: Dapper allocates [pending] more than ODX.

+
+
+
+

Why the orange bar matters

+

A fixed number of connections. The same requests. Only the hold time differs.

+ +
+ + +
+
- -
-

Parameters from arguments

-

The name comes from the variable. For a stored procedure it is matched to the real one.

-
-
-
Post[] posts = await connectionFactory
-    .Command("select * from posts where author = @Author order by id")
-    .AddParam(search.Author) // name and type inferred from the member
-    .Map<Post>()
-    .ToArrayAsync(cancellationToken);
-

A stored procedure (SQL Server)

-
=> db.StoredProcedure("[dbo].[SearchPosts]")
-    .AddParam(author)
-    .AddParam(titleContains)
-    .Map<Post>()
-    .ToListAsync(ct);
+
+

Open late, close early

+

A call takes a connection only while it runs, and never keeps yours.

+
+
+ +From a factory +factory +pool + +closed +open +ODX opens +ODX closes +the call + + +disposed +a pool's connection is given back +Your connection, open +you +still yours +open +the call +stays open +
-
- - your argument - - titleContains - - procedure declares - @author - - @title_contains - 1exactly - 2ignoring case - - 3ignoring case - and underscores - - then: a common prefix dropped,then a chain's shorter endings - ✗ - ✗ - ✓ - - - - a literal needs a name: - AddParam("author", 42) - no match: throws and says what it declares - - -

Names read once per factory.

+
+
    +
  • From a factory: opened for the call, then given back.
  • +
  • Your connection: left as it was found. Still yours.
  • +
-
-

Correct by default

-

Errors are loud. Declarations are hard rules.

-
-
-
public record Post
-{
-    [Column("id", Order = 0)]
-    public required int Id { get; init; }
-
-    [Column("title", Order = 1)]
-    public string Title { get; init; } = "";
+  

One call, two ways to wait

+

The database behaves the same. Only the worker's choice differs.

+
+ + + + + + + + + + + + what the database and network do + open + the database runs the query + rows + + rows + + rows + done + still on the way + still on the way + - // Not mapped: no column is ever - // read into it. - [NotMapped] - public string Slug { get; init; } = "unset"; -}
-
var posts = await command.SingleResult()
-    .Map<Post>()
-    .ToListAsync(cancellationToken);
-
-
- -null into a non-nullable member -Postrow 0 - -int Id -int Id✓ -1row 1 - -int Id -int Id✓ -2row 2 - -int Id -int Id✗ -null -ValueMappingException -Post, row 2 -int? gives null -Later result sets: read through -result set 1result set 2 -an error - -ODX keeps reading -✗ -set 1: read -thrown, not lost -First set only -.SingleResult() -result set 1result set 2 -not read - -stop -stops after set 1 -set 2: not read -Declarations are hard rules -[Column("id", Order = 0)]Idread as declared✓ -[Column("title", Order = 1)]Titleread as declared✓ -[NotMapped]Slugno column is readkeeps "unset" -[Column("title", Order = 1)]Titledeclared, but missingthrows ValueMappingException - + + Default + workerconnection + Read() + + free while it is awaited + + + + + Option + workerconnection + .AsyncReads() + + free while it is awaited + + + + + + + connection held longer + + + + + + + + waits for the rows + steps away, comes back + tied up: 1 + tied up: 0 + + same finish + calm serverbusy server + + + working + waiting, holding the worker + free to serve others + in line for a free worker + + Most rows are already there. Gaps are rare. + +
+
DefaultShortest hold on the connection.
A worker pauses during a rare gap.
+
Option, one word per callNo worker ever pauses.
Under load the connection can be held longer.
-
-

Connection ownership

-

Open if needed. Close only what you opened.

-
-
-
// A closed connection is opened for the call
-// and closed again afterwards.
-await connection.CloseAsync();
-await connection.Command("select 1")
-    .ExecuteScalarAsync(cancellationToken);
+  

What the choice costs

+

Time per call. Shorter is better.

+
DefaultThe option
+
+ +
Rows ready +
+
77.4 µs
+
80.0 µs
+
+ same
-// A connection that was already open stays open. -await connection.OpenAsync(cancellationToken); -await connection.Command("select 1") - .ExecuteScalarAsync(cancellationToken);
-
-
- -1  From a factory -factory -pool - -closed -open -ODX opens -ODX closes -the call - - -disposed -a pool's connection is given back -2  Your connection, closed -you -still yours -closed -open -ODX opens -ODX closes -the call -closed again -never disposed -3  Your connection, open -you -still yours -open -the call -stays open -4  When the query fails -From a factory -✗ fails - - -disposedback to the pool -Your connection,closed -✗ fails - - -closed againnever disposed -Your connection,open -✗ fails - - -stays openstill yours -A SQL error, a timeout or a cancel:the connection is put back, then the exception reaches you. - -
-
- -
+
Real SQL Server, slow link +
+
538.3 ms
+
538.2 ms
+
+ same
- -
-

Why hold time matters

-

A fixed number of connections. The same requests. Only the hold time differs.

- Illustrative model: not measured - -
- - +
Busy server and network waits +
+
279.8 µs
+
2,227 µs
+
+ 8.0 times as long
-

Requests wait for a free connection. A connection pool has a maximum size, and a database a limited number of workers. Queueing at scale was not measured, and neither was the gain from releasing a thread.

+

.AsyncReads()  one call opts in

- - -
-

One set of rows

-

The usual stack copies rows into DTOs. Here they are read once.

+
+

Rows are read once

+

The usual stack copies rows into DTOs. Here they are read once.

Copies of copies, or one copy Two lanes read left to right, the classic stack on top and ODX below, with the database, the serializer and the JSON in the same places. Classic lane: the database, then a repository that reads the rows into entities and a list, the first set of row objects; then a service that copies the entities into DTOs and another list, the second set; then the serializer and the JSON. A caption says there are two sets of row objects and two lists, and the garbage collector takes them all after the response. ODX lane: the database, then the command factory, whose rows are read once into Post objects in pooled arrays, the only set; then the serializer and the JSON. Below the pooled arrays is the array pool: the arrays are rented from it for the read and go back to it after the response. A caption says there is one set of row objects and the arrays are reused by later requests. The figure shows no measurements. @@ -1190,20 +1247,524 @@

One set of rows

back after the response - - array pool - + + array pool + + + One set of row objects. The arrays are reused by later requests. + +

Whole request, JSON out|time: one copy [pending] against copies [pending]|memory: [pending] against [pending]

+ +
+ +
+

Stop when you have enough

+

The database keeps sending rows unless you tell it to stop.

+
+ + + + + + Without it + every row is sent + + CancelOnEarlyStop() + the rest is discarded + + + + cancel + +
+
+

First of 3 million rows, SQL Server LocalDB, ms. Shorter is better.

+
Without it
202
+
Opt in
0.4
+
+ +
+ +
+

Wrong data fails loudly

+

You find out on that row, not three screens later.

+
+
+ +null into a non-nullable member +Postrow 0 + +int Id +int Id✓ +1row 1 + +int Id +int Id✓ +2row 2 + +int Id +int Id✗ +null +ValueMappingException +Post, row 2 +int? gives null +Later result sets: read through +result set 1result set 2 +an error + +ODX keeps reading +✗ +set 1: read +thrown, not lost + +
+
+
    +
  • A null never slips into a field that is never empty. The error names the row.
  • +
  • An error in a later result set is thrown, not lost.
  • +
+
+
+ +
+ +
+

Less code. Hand-written speed. Calm under load.

+
+
5 lines, not 22 +
Plain ADO.NET
22
+
ODX
5
+
+
As fast as hand-written +
Hand-written
[pending]
+
ODX
[pending]
+
+
Short hold, one copy + + connection in use + one set of rows + +
+
+
dotnet add package Open.Database.Extensions.Core
+

open-net-libraries.github.io/Open.Database.Extensions

+

Questions

+ +
+ +
+

Go deeper

+

Each card answers a question. Pick one.

+
+

In this deck, in the order of the slides they back up

+ A1  The 22 linesThe plain ADO.NET code in full + A2  Setup once, code per callODX, EF Core and Dapper side by side + A3  How little codeFour tasks, four libraries + A4  Generator detailsWhen it does not generate; opting out + A5  A query as a valueDefine once, bind where it runs + A6  Parameters and mapping rulesNames, stored procedures, declared columns + A7  Connection ownershipClosed, open and failing connections + A8  Buffered resultsIn a controller, no service layer + A9  The journey of a resultFrom the query to the end of the request + A10  While it fillsReading chunks as they are published + A11  Streaming, safelyRow by row; the stall timeout + A12  Stop early: the detailsThe snippet, when it does not help, the limits + A13  Busy thread poolClose-up of the queue after a gap + A14  Async reads in fullFour conditions, memory, a 100 MB value + A15  How the numbers were madeMethod; where ODX is not faster; SQLite + A16  Cost per columnWhat one more column costs + A17  PoolingRows go into rented arrays and back + A18  Clearing pooled arraysWhat is cleared, and why + A19  Packages and pipelinesPackages, frameworks, channels, dataflow +

In the docs

+Docs articleMapping rowsRenamed columns, records and constructors, and null policy. +Docs articleShaping rowsWhen the row you want is not the row the query returns: recipes, no new API. +Docs articleExpressive commandsFactory or connection, defining a query once, parameters and terminals. +Docs articleComing from DapperThe steps side by side, and who handles the connection. +Docs articleWith minimal APIsThe same command factory in an endpoint, no service layer. +
+ +
+
+ ← Go deeper +

The problem

+

One author's posts, with plain ADO.NET: 22 lines.

+
+
+ +
var posts = new List<Post>();
+await using var connection = new SqliteConnection(connectionString);
+await connection.OpenAsync(cancellationToken);
+await using var command = connection.CreateCommand();
+command.CommandText =
+    "select id, author, title, body from posts "
+    + "where author = @author order by id";
+var parameter = command.CreateParameter();
+parameter.ParameterName = "@author";
+parameter.Value = author;
+command.Parameters.Add(parameter);
+await using var reader = await command.ExecuteReaderAsync(cancellationToken);
+while (await reader.ReadAsync(cancellationToken))
+{
+    posts.Add(new Post
+    {
+        Id = reader.GetInt32(0),
+        Author = reader.GetInt32(1),
+        Title = reader.GetString(2),
+        Body = reader.IsDBNull(3) ? null : reader.GetString(3),
+    });
+}
+
← the part you meant to write
+
+
+ Connection + Command + Parameter + Read loop + Column copying + Disposal +
+
+ +
+
+ ← Go deeper +

Setup once, code per call

+

An ORM looks like less code because the setup is written somewhere else.

+
+
+

ODX: not an ORM. Define once, you write the SQL

+
static readonly MappedDbQuery<Post> AllPosts
+    = DbQuery.Text(AllPostsSql).Map<Post>();
+
+// per call
+=> AllPosts.Using(connectionFactory)
+    .ToListAsync(cancellationToken);
+
+
+

EF Core: an ORM with change tracking and SaveChanges.
A context first, then LINQ

+
// per call
+=> db.Posts.OrderBy(static p => p.Id)
+    .ToListAsync(ct);
+
+
+
+

Lines you write for task 1, rows to a list: once, and per call

+
onceper call
+ +
ODX
7 per call, 1–3 once
+
EF Core
6 per call, 5 once+ configuration, registration: not counted
+
Dapper
9 per call, no setup
+
ADO.NET
22 per call, no setup
+
+

Dapper and ADO.NET create the connection in every call.

+ +
+
+ ← Go deeper +

How little code

+

Four tasks, all async. Lines per method, signature to closing brace.
EF Core's context is not counted (see Setup once, code per call).

+
ODXDapperEF CoreADO.NET
+
1. Rows to a list
+
7
+
9
+
6
+
22
+
2. Filter in SQL, project in C#,
async stream
+
10
+
14
+
8
+
22
+
3. One author's rows in memory,
then LINQ
+
15
+
15
+
13
+
26
+
4. A stored procedure,
two parameters
+
11
+
14
+
12
+
29
+

Per-call methods only. Blank lines and comments not counted. The ODX connection factory and the EF Core context are set up once:
see Setup once, code per call. Every snippet is compiled.

+ +
+ +
+ ← Go deeper +

Generator details

+

What the build does when it can, and when it cannot.

+
+
Where it cannot generateA call inside a generic method, or a model that is a single value. A runtime map is built once per result shape and cached.
+
Opt out<OdxGenerateMaps>false</OdxGenerateMaps> in the project file.
+
RequiresC# 12 or later.
+
+

Annotations

+
    +
  • An annotated model is read at fixed positions: the same as hand-written.
  • +
  • A model without annotations pays a small check of column names once per query, about 1 ns per column. Annotate it, and the check is skipped.
  • +
+ +
+
+ ← Go deeper +

Define once, bind where it runs

+

A query is a value: immutable, no connection, safe in a static field.

+
// Recommended.
+static readonly MappedDbQuery<Post> ByAuthor
+    = DbQuery.Text(ListSql).Map<Post>();
+
+public ValueTask<List<Post>> ByAuthorAsync(
+    int author,
+    CancellationToken cancellationToken)
+    => ByAuthor.Using(connectionFactory)
+        .AddParam(author)
+        .ToListAsync(cancellationToken);
+

One-row call at 20 columns, µs, runtime map. Shorter is better.

+
Map cached, reused
+
0.28 about 3,100 times
+
New RowMap<T> at the call site
+
870
+

Building the map: 190 to 870 µs for 1 to 20 columns.
With the generator, at build time, except in a generic method.

+ +
+
+ ← Go deeper +

Parameters from arguments

+

The name comes from the variable. For a stored procedure it is matched to the real one.

+
+
+
Post[] posts = await connectionFactory
+    .Command("select * from posts where author = @Author order by id")
+    .AddParam(search.Author) // name and type inferred from the member
+    .Map<Post>()
+    .ToArrayAsync(cancellationToken);
+

A stored procedure (SQL Server)

+
=> db.StoredProcedure("[dbo].[SearchPosts]")
+    .AddParam(author)
+    .AddParam(titleContains)
+    .Map<Post>()
+    .ToListAsync(ct);
+
+
+ + your argument + + titleContains + + procedure declares + @author + + @title_contains + 1exactly + 2ignoring case + + 3ignoring case + and underscores + + then: a common prefix dropped,then a chain's shorter endings + ✗ + ✗ + ✓ + + + + a literal needs a name: + AddParam("author", 42) + no match: throws and says what it declares + + +

Names read once per factory.

+
+
+ +
+
+ ← Go deeper +

Correct by default

+

Errors are loud. Declarations are hard rules.

+
+
+
public record Post
+{
+    [Column("id", Order = 0)]
+    public required int Id { get; init; }
+
+    [Column("title", Order = 1)]
+    public string Title { get; init; } = "";
 
-  One set of row objects. The arrays are reused by later requests.
-
+    // Not mapped: no column is ever
+    // read into it.
+    [NotMapped]
+    public string Slug { get; init; } = "unset";
+}
+
var posts = await command.SingleResult()
+    .Map<Post>()
+    .ToListAsync(cancellationToken);
+
+
+ +null into a non-nullable member +Postrow 0 + +int Id +int Id✓ +1row 1 + +int Id +int Id✓ +2row 2 + +int Id +int Id✗ +null +ValueMappingException +Post, row 2 +int? gives null +Later result sets: read through +result set 1result set 2 +an error + +ODX keeps reading +✗ +set 1: read +thrown, not lost +First set only +.SingleResult() +result set 1result set 2 +not read + +stop +stops after set 1 +set 2: not read +Declarations are hard rules +[Column("id", Order = 0)]Idread as declared✓ +[Column("title", Order = 1)]Titleread as declared✓ +[NotMapped]Slugno column is readkeeps "unset" +[Column("title", Order = 1)]Titledeclared, but missingthrows ValueMappingException + +
+
+
+ ← Go deeper +

Connection ownership

+

Open if needed. Close only what you opened.

+
+
+
// A closed connection is opened for the call
+// and closed again afterwards.
+await connection.CloseAsync();
+await connection.Command("select 1")
+    .ExecuteScalarAsync(cancellationToken);
 
-
-
+// A connection that was already open stays open. +await connection.OpenAsync(cancellationToken); +await connection.Command("select 1") + .ExecuteScalarAsync(cancellationToken);
+
+
+ +1  From a factory +factory +pool + +closed +open +ODX opens +ODX closes +the call + + +disposed +a pool's connection is given back +2  Your connection, closed +you +still yours +closed +open +ODX opens +ODX closes +the call +closed again +never disposed +3  Your connection, open +you +still yours +open +the call +stays open +4  When the query fails +From a factory +✗ fails + + +disposedback to the pool +Your connection,closed +✗ fails + + +closed againnever disposed +Your connection,open +✗ fails + + +stays openstill yours +A SQL error, a timeout or a cancel:the connection is put back, then the exception reaches you. + +
+
+ +
+
+ ← Go deeper

Buffered results, no service layer

The controller calls the query and returns the pooled rows.

@@ -1231,7 +1792,7 @@

Buffered results, no service layer

  • ToArrayAsync: fastest to a finished array.
    One exact copy.
  • ToPooledBuffer: no final copy.
    Readable while it fills.
    Arrays back to the pool on dispose.
  • - +
    - -
    +
    + ← Go deeper

    The journey of a result

    Query, controller, response, dispose: where the rows are copied.

    @@ -1433,15 +1994,15 @@

    The journey of a result

    ToPooledBufferhere: Items, after the last rowDBcontrollerserializeJSONdispose: back to the poolconnection heldtotal time, until you are done with the rowsdatabaseRead: all rows into pooledchunks in a background task;the call returns at once;connection released at last rowHand over: no copy and no extraarray, the controller readsthe chunks themselvesRespond: serializes the chunksEnd: the buffer is disposedafter the response; chunks goback to the pool, reused next no copyno extra arrayarrays reused -

    Full request, JSON response|total time: ToPooledBuffer [rc.16] against ToArrayAsync [rc.16]|memory: [rc.16] against [rc.16]

    +

    Full request, JSON response|total time: ToPooledBuffer [pending] against ToArrayAsync [pending]|memory: [pending] against [pending]

    - -
    +
    + ← Go deeper

    While it fills

    Read each chunk as it is published. Dispose sends the chunks back.

    @@ -1585,16 +2146,15 @@

    While it fills

    await foreach (var post in buffer.AsAsyncEnumerable(ct))enumerated: each chunkDBcontrollerserializeJSONdispose: back to the poolconnection heldtotal time, until you are done with the rowsdatabaseRead: all rows into pooledchunks in the background;connection released at last rowEnumerate: the controller takeseach chunk as it is published,never a half-filled oneRespond: serializes each chunkEnd: the buffer is disposed;chunks go back to the poolawait buffer.ItemsItems: waits for all rowsDBcontrollerserializeJSONdispose: back to the poolconnection heldtotal time, until you are done with the rowsdatabaseRead: all rows into pooledchunks in a background task;the call returns at once;connection released at last rowHand over: no copy and no extraarray, the controller readsthe chunks themselvesRespond: serializes the chunksEnd: the buffer is disposedafter the response; chunks goback to the pool, reused nextwhole chunks, as each is published -

    Full request, JSON response|total time: enumerated [rc.16] against Items [rc.16]

    +

    Full request, JSON response|total time: enumerated [pending] against Items [pending]

    - - -
    -

    Streaming, safely

    -

    Stream(stallTimeout) and StreamBuffered: use them to stop early.
    To read all rows, use ToArrayAsync.

    +
    + ← Go deeper +

    Streaming, safely

    +

    Stream(stallTimeout) and StreamBuffered: use them to stop early.
    To read all rows, use ToArrayAsync.

    // Only to stop early: Stream holds the connection
    @@ -1645,9 +2205,8 @@ 

    Streaming, safely

    +
    + ← Go deeper

    Stop early

    CancelOnEarlyStop(): opt in, when the query returns far more rows than you need.

    @@ -1697,23 +2256,22 @@

    Stop early

    Do not use it for a TOP 1 or a key lookup; there is nothing to save. After a cancel, a later statement of the batch may or may not run, and the command is refused with a transaction, an output parameter or an ambient TransactionScope. Its error is not reported either way, and a BEGIN TRAN in the SQL or XACT_ABORT is not detected: do not use it with them. It was verified on SQL Server LocalDB, and with SQLite for usability only.

    - - -
    -

    Greedy or polite

    -

    Who holds the connection longer, when the thread pool is busy.

    +
    + ← Go deeper +

    Busy thread pool, close up

    +

    Who holds the connection longer, when every worker is busy.

    Illustrative: not to scale - + - Greedy + Default Read() the default - Polite + Option ReadAsync() AsyncReads() @@ -1804,13 +2362,12 @@

    Greedy or polite

    - - -
    +
    + ← Go deeper

    Async done right

    Row reads are synchronous by default.
    AsyncReads() opts in to full async.

    @@ -1870,9 +2427,8 @@

    Async done right

    The hazard is a busy thread pool plus a wait for data: with a 20 µs wait every 100 rows, AsyncReads took 2.2 ms against 0.28 ms for the default. Releasing a thread while a row is on the wire was not measured. The second step shows a real SQL Server over a slow link: the same time either way, and on Map(Func) 73% more memory with AsyncReads(). One 100 MB value is the dangerous case on raw SqlClient: 48.0 s with raw SqlClient ReadAsync against 8.86 s with raw Read(), CommandBehavior.Default, one 100 MB value over a simulated slow link.

    - - -
    +
    + ← Go deeper

    Honest benchmarks

    Every page says how it was measured and where ODX is not faster.

    @@ -1893,114 +2449,62 @@

    Honest benchmarks

    - -
    -

    Get started

    -

    Version 11.0 on NuGet.

    -
    dotnet add package Open.Database.Extensions.Core
    - - - - - - -
    PackageUse it for
    Open.Database.Extensions.CoreEverything, provider-agnostic
    Open.Database.Extensions.MSSqlClientSqlConnectionFactory, SQL Server
    Open.Database.Extensions.ChannelReading into channels
    Open.Database.Extensions.DataflowReading into dataflow blocks
    -

    Core targets netstandard2.0, netstandard2.1, net10.0, net11.0. MSSqlClient: net472, net10.0, net11.0. MIT license.

    -

    Moving from 10.x: Coming from earlier versions

    -

    open-net-libraries.github.io/Open.Database.Extensions

    - -
    - -
    -

    Go deeper

    -

    Pick a topic.

    -
    -

    In this deck

    - In this deckHow little codeLines per method: four tasks, four libraries. - In this deckCost per columnWhat one more column costs, from 1 to 20 columns. - In this deckPoolingRows go into rented arrays, and the arrays go back. - In this deckClearing pooled arraysWhat is cleared when arrays go back, and why. - In this deckPipelinesChannels and Dataflow over Map<T>(). -

    In the docs

    - Docs articleMapping rowsRenamed columns, records and constructors, and null policy. - Docs articleShaping rowsWhen the row you want is not the row the query returns: recipes, no new API. - Docs articleExpressive commandsFactory or connection, defining a query once, parameters and terminals. - Docs articleComing from DapperThe steps side by side, and who handles the connection. - Docs articleWith minimal APIsThe same command factory in an endpoint, no service layer. + ← Go deeper +

    SQLite and memory

    +

    The same shape on a second database, and the memory side of the synthetic run.

    +
    +
    +

    SQLite file, 10,000 rows of 20 columns, time per call

    +
    Plain ADO.NET, same objects: [pending] msEach method's extra time
    +
    +
    ODX Map<T>()
    +[pending] ms
    +
    Hand-written
    +[pending] ms
    +
    Dapper.AOT
    +[pending] ms
    +
    Dapper
    +[pending] ms
    +
    +

    Memory on SQLite: Dapper allocates [pending] more than ODX.

    +
    +
    +

    Memory allocated per call (synthetic, 20 columns, 1,000 rows)

    +
    +
    ODX, hand-written, Dapper.AOT[pending] KB
    +
    Dapper[pending] KB
    +
    +
    -
    - - -
    -

    How little code

    -

    Four tasks, all async. Lines per method, signature to closing brace.
    EF Core's context is not counted (see Setup once, code per call).

    - ← Go deeper -
    ODXDapperEF CoreADO.NET
    -
    1. Rows to a list
    -
    7
    -
    9
    -
    6
    -
    22
    -
    2. Filter in SQL, project in C#,
    async stream
    -
    10
    -
    14
    -
    8
    -
    22
    -
    3. One author's rows in memory,
    then LINQ
    -
    15
    -
    15
    -
    13
    -
    26
    -
    4. A stored procedure,
    two parameters
    -
    11
    -
    14
    -
    12
    -
    29
    -

    Per-call methods only. Blank lines and comments not counted. The ODX connection factory and the EF Core context are set up once:
    see Setup once, code per call. Every snippet is compiled.

    -
    - - -
    +
    + ← Go deeper

    Cost per column

    Nanoseconds for one more cell. Synthetic reader, 1,000 rows, 1 to 20 columns.

    - ← Go deeper
    1 columntime for 1,000 rows, µs20 columnscost per cell
    - -
    Hand-written selector[rc.16]
    [rc.16][rc.16] ns
    - -
    ODX Map<T>()[rc.16]
    [rc.16][rc.16] ns
    - -
    object[] rows[rc.16]
    [rc.16][rc.16] ns
    - -
    Dapper Query<T>[rc.16]
    [rc.16][rc.16] ns
    + +
    Hand-written selector[pending]
    [pending][pending] ns
    + +
    ODX Map<T>()[pending]
    [pending][pending] ns
    + +
    object[] rows[pending]
    [pending][pending] ns
    + +
    Dapper Query<T>[pending]
    [pending][pending] ns
    - -

    ODX is [rc.16] times faster than Dapper at 1 column, [rc.16] times at 20.
    Each line is straight: the cost per cell is the time at 20 columns minus the time at 1 column, divided by the cells added.

    + +

    ODX is [pending] times faster than Dapper at 1 column, [pending] times at 20.
    Each line is straight: the cost per cell is the time at 20 columns minus the time at 1 column, divided by the cells added.

    - - -
    -

    Pooling

    -

    Rows go into arrays rented from a pool, and the arrays go back.

    - ← Go deeper +
    + ← Go deeper +

    Pooling

    +

    Rows go into arrays rented from a pool, and the arrays go back.

    await using PooledBuffer<int> buffer = connectionFactory
    @@ -2040,13 +2544,11 @@ 

    Pooling

    Pooling is a secondary detail: it keeps memory use down, and you do not need to think about it to use the library. What happens to the arrays when they go back is the next slide, Clearing pooled arrays.

    - - -
    -

    Clearing pooled arrays

    -

    What is cleared, and why.

    - ← Go deeper - +
    + ← Go deeper +

    Clearing pooled arrays

    +

    What is cleared, and why.

    + @@ -2101,12 +2603,30 @@

    Clearing pooled arrays

    Only the written part is cleared, and never in the read loop that holds the connection; it happens when the buffer is disposed. Large arrays go to a background queue so the caller is not held, and if that queue is full the caller clears the array itself rather than put a dirty array back in the pool.

    - - -
    +
    + ← Go deeper +

    Get started

    +

    Version 11.0 on NuGet.

    +
    dotnet add package Open.Database.Extensions.Core
    + + + + + + +
    PackageUse it for
    Open.Database.Extensions.CoreEverything, provider-agnostic
    Open.Database.Extensions.MSSqlClientSqlConnectionFactory, SQL Server
    Open.Database.Extensions.ChannelReading into channels
    Open.Database.Extensions.DataflowReading into dataflow blocks
    +

    Core targets netstandard2.0, netstandard2.1, net10.0, net11.0. MSSqlClient: net472, net10.0, net11.0. MIT license.

    +

    Moving from 10.x: Coming from earlier versions

    +

    open-net-libraries.github.io/Open.Database.Extensions

    + +
    +
    + ← Go deeper

    Pipelines

    Channels and Dataflow over Map<T>(). Use one when something downstream needs it.
    For a plain list, use ToListAsync().

    - ← Go deeper
    ChannelReader<Post> reader = connectionFactory
    @@ -2348,6 +2868,7 @@ 

    9: { sel: ".mv", w: [[0, 900], [900, 1500], [1500, 3300], [3300, 3300]] }, 10: { sel: ".mv,.coB-a", w: [[0, 2700], [2700, 6500], [0, 2200], [2200, 6500], [0, 3000], [3000, 5000]] }, 11: { sel: ".mv,.coB-a", w: [[0, 5000], [5000, 9000], [0, 4300], [4300, 9000]] }, + "11b": { sel: ".mv,.coB-a", w: [[0, 5000], [5000, 9000], [0, 6000]] }, 13: { sel: ".nsl-hl", w: [[0, 1400], [1400, 2800], [2800, 5200]] }, 17: { sel: ".mv", inStep: true, w: [null, [0, 1200], [1200, 3500], [3500, 5000]] }, 26: { sel: ".mv", w: [[0, 2100], [2100, 4200]] }, @@ -2368,7 +2889,7 @@

    // Apply the phase for step s of slide i: play it (forward one step) or hold its end state. Returns the animations it controls. function phApply(i, s, play) { phClear(i); - var cfg = PH[i + 1], all = []; + var cfg = PH[slides[i].getAttribute("data-ph")], all = []; if (!cfg) return all; cfg.lanes.forEach(function (lane) { var w = lane.w[s], list = phAnims(i, cfg, lane); @@ -2390,7 +2911,7 @@

    } // Replay: restart this slide's animations from the start of the current step's phase. The step does not change. function replay() { - var i = cur, skip = PH[i + 1] ? phApply(i, st, true) : []; + var i = cur, skip = PH[slides[i].getAttribute("data-ph")] ? phApply(i, st, true) : []; if (typeof CSSAnimation !== "undefined") { slides[i].getAnimations({ subtree: true }).forEach(function (a) { if (a instanceof CSSAnimation && skip.indexOf(a) < 0) { a.cancel(); a.play(); } @@ -2443,8 +2964,8 @@

    return { svg: svg, H: H, plan: plan(H), fills: fills, circles: circles }; } var P = [ - panel(document.getElementById("pL"), "Short hold: sync reads", "var(--a)", 1.6), - panel(document.getElementById("pR"), "Long hold: async reads, busy pool", "var(--conn)", 2.8) + panel(document.getElementById("pL"), "Short hold", "var(--a)", 1.6), + panel(document.getElementById("pR"), "Long hold", "var(--conn)", 2.8) ]; function setState(p, t) { var w = []; @@ -2495,6 +3016,9 @@

    window.addEventListener("beforeprint", function () { stop(); P.forEach(function (p) { p.svg.classList.remove("fade"); }); setAll(END); }); })(); + window.addEventListener("beforeprint", function () { Array.prototype.forEach.call(document.querySelectorAll(".step"), function (s) { s.classList.add("shown"); }); }); + window.addEventListener("afterprint", function () { render(); }); + fit(); var h0 = fromHash(); go(Math.max(0, Math.min(total - 1, h0.n)), "init", h0.s); From f36e500b543bf3f7ab896a727a00548d273e2f24 Mon Sep 17 00:00:00 2001 From: electricessence <5899455+electricessence@users.noreply.github.com> Date: Tue, 1 Dec 2026 09:32:27 -0800 Subject: [PATCH 2/2] Deck: fill the rc.16 numbers Synthetic (20 columns x 1,000 rows), real databases (SQL Server and SQLite, 10,000 rows) and cost per column, from the rc.16 run. The ODX figures are the plain Map() on an unannotated model, except cost per column, which measured the annotated model. The real-database text now says what the run shows: ODX level with hand-written and ahead of Dapper.AOT and Dapper. Still pending: Dapper.AOT on the synthetic chart and the journey figures. Co-Authored-By: Claude Opus 5.5 --- docsite/presentation/index.html | 60 ++++++++++++++++----------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/docsite/presentation/index.html b/docsite/presentation/index.html index c8eec70a..63bde124 100644 --- a/docsite/presentation/index.html +++ b/docsite/presentation/index.html @@ -886,16 +886,16 @@

    How fast

    -
    Hand-written[pending]
    -
    ODX Map<T>()[pending]
    +
    Hand-written40.15 µs
    +
    ODX Map<T>()40.26 µs
    Dapper.AOT[pending]
    -
    Dapper[pending]
    +
    Dapper170.60 µs
    -
    [pending]×less time per call
    than Dapper
    -
    [pending]×less memory
    than Dapper
    +
    4.2×less time per call
    than Dapper
    +
    2.4×less memory
    than Dapper

    Level with hand-written. Ahead of Dapper.AOT and Dapper on mapping.

    @@ -904,28 +904,28 @@

    How fast

    Say the limit aloud, once: this is the library's own cost, with no database in the way. Read the verdict, not the bars. Next slide: with a real database.

    Setup: a synthetic reader, 20 columns, 1,000 rows, the same query and the same rows for every library, one process per case. "Time per call" is how long one call takes from start to finish, which is also how long its connection is in use. Dapper.AOT was run through its intercepted path, as it is meant to be used. The generated reader goes through its own method, with an identical hand-written copy as the control.

    Memory allocated per call is the same for ODX, hand-written and Dapper.AOT, and about twice as much for Dapper; the bars are in the appendix (A15). The error margins are on the benchmark page.

    -

    Dapper.AOT claim, stated honestly: generated ODX is ahead of Dapper.AOT on mapping. On a real database the two are level, within noise; that is the next slide.

    +

    Dapper.AOT claim, stated honestly: generated ODX is ahead of Dapper.AOT on mapping. On a real database ODX is ahead too, by less; that is the next slide.

    On a real database

    SQL Server LocalDB. 10,000 rows of 20 columns. Time per call.

    -
    The database itself: plain ADO.NET building the same objects, [pending] msEach method's extra time on top
    +
    The database itself: plain ADO.NET building the same objects, 22.91 msEach method's extra time on top
    -
    ODX Map<T>()
    +[pending] ms
    -
    Hand-written
    +[pending] ms
    -
    Dapper.AOT
    +[pending] ms
    -
    Dapper
    +[pending] ms
    +
    ODX Map<T>()
    +0.40 ms
    +
    Hand-written
    +0.37 ms
    +
    Dapper.AOT
    +0.75 ms
    +
    Dapper
    +4.20 ms
    -

    ODX, hand-written and Dapper.AOT: level, within noise.

    -

    Memory: Dapper allocates [pending] more than ODX.

    +

    ODX level with hand-written. Ahead of Dapper.AOT and Dapper.

    +

    Memory: Dapper allocates 29% more than ODX.

    @@ -1349,8 +1349,8 @@

    Less code. Hand-written speed. Calm under load.

    ODX
    5
    As fast as hand-written -
    Hand-written
    [pending]
    -
    ODX
    [pending]
    +
    Hand-written
    40.15
    +
    ODX
    40.26
    Short hold, one copy @@ -2456,25 +2456,25 @@

    SQLite and memory

    SQLite file, 10,000 rows of 20 columns, time per call

    -
    Plain ADO.NET, same objects: [pending] msEach method's extra time
    +
    Plain ADO.NET, same objects: 24.77 msEach method's extra time
    -
    ODX Map<T>()
    +[pending] ms
    -
    Hand-written
    +[pending] ms
    -
    Dapper.AOT
    +[pending] ms
    -
    Dapper
    +[pending] ms
    +
    ODX Map<T>()
    −0.12 ms
    +
    Hand-written
    −0.10 ms
    +
    Dapper.AOT
    +2.01 ms
    +
    Dapper
    +4.58 ms
    -

    Memory on SQLite: Dapper allocates [pending] more than ODX.

    +

    Memory on SQLite: Dapper allocates 24% more than ODX.
    Below zero: faster than the plain ADO.NET run by less than the run's noise.

    Memory allocated per call (synthetic, 20 columns, 1,000 rows)

    -
    ODX, hand-written, Dapper.AOT[pending] KB
    -
    Dapper[pending] KB
    +
    ODX, hand-written, Dapper.AOT227 KB
    +
    Dapper548 KB
    @@ -2486,16 +2486,16 @@

    Cost per column

    1 columntime for 1,000 rows, µs20 columnscost per cell
    -
    Hand-written selector[pending]
    [pending][pending] ns
    +
    Hand-written selector5.85
    43.661.99 ns
    -
    ODX Map<T>()[pending]
    [pending][pending] ns
    +
    ODX Map<T>()5.84
    42.851.95 ns
    -
    object[] rows[pending]
    [pending][pending] ns
    +
    object[] rows11.26
    163.037.99 ns
    -
    Dapper Query<T>[pending]
    [pending][pending] ns
    +
    Dapper Query<T>15.84
    163.247.76 ns
    -

    ODX is [pending] times faster than Dapper at 1 column, [pending] times at 20.
    Each line is straight: the cost per cell is the time at 20 columns minus the time at 1 column, divided by the cells added.

    +

    ODX is 2.7 times faster than Dapper at 1 column, 3.8 times at 20.
    Each line is straight: the cost per cell is the time at 20 columns minus the time at 1 column, divided by the cells added.