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.
+
+
+
+
+
+
+
+
+
+
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
+
-
-
connectionFactory is created once per application.
- The five ODX lines do the same job as the 22. AddParam(author) names the parameter author after the variable, so you do not spell it twice; AddParam("author", 42) names it yourself.
- The line counts come from the README: they count the lines you write, without blank lines and without the declaration of the value.
+ Same result. This is all you write. Do not explain AddParam naming unless asked: it names the parameter author after the variable, and AddParam("author", 42) names it yourself.
+ Line counts come from the README: the lines you write, without blank lines and without the declaration of the value. The connection factory is created once per application.
+ This is the only code in the first eleven slides.
-
- 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
-
once per call
-
-
-
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 everything the library writes the SQL
+
+
ADO.NET Dapper ODX EF Core
+
You write the SQL ✓ ✓ ✓ —
+
Lines per call 22 9 7 6
+
Tracks changes, saves for you — — — ✓
-
Dapper and ADO.NET create the connection in every call.
- You may be thinking that an ORM such as EF Core is short too. It is, per call; the setup is just written somewhere else.
- EF Core does need setup. There is a context class, a set for the model, configuration and registration, and writes also need a save call. After that, a query is short and clean, and the table on the bonus slide How little code shows it.
- ODX sets up differently, because it is not an ORM. There is no change tracking and no SaveChanges; you write the SQL. You define the query once, as a static value, with no context at all. Where it runs, the code is a few lines: bind the connection factory and the values, then pick the terminal.
- Counts: 5 lines for the sample context, 2 for the static query. The EF Core configuration and registration are not in the samples, so they have no number here.
+ Answer "why not EF Core, why not Dapper" before it is asked. EF Core writes the SQL for you and tracks changes. Dapper and ODX let you write it. ODX asks for less code than Dapper, and the next slides show what it costs to run.
+ Say the con plainly: ODX has no change tracking and no generated SQL. If you want those, EF Core is the tool. If the right-hand label reads as a criticism to this audience, it already says "the library writes the SQL".
+ Lines per call are for task 1, rows to a list, from the how-little-code page (22 plain ADO.NET, 9 Dapper, 7 ODX, 6 EF Core). EF Core is shorter per call because its setup is written somewhere else (a context, configuration, registration, none of it counted here). Setup once, code per call is appendix A2; four tasks side by side is A3.
-
- 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
+
+ open take a connection run the query the database works rows come back in bursts close give it back
+
+ connection in use
+
+
+ your code
+
+
+
+ Remember the orange bar. The rest of the deck makes it short and the middle cheap.
+
- Less code usually costs speed. So first: what is the fastest this can possibly be?
- A hand-written selector is code you wrote for one known shape, so the column positions and types are in the code. Nothing is looked up, compared or converted while it runs. That is the fastest way to read rows with ADO.NET, and the ceiling every mapping library is measured against.
- The catch is the work: you write it for every query and keep it in step with the SQL. Numbers: synthetic reader, no database.
+ This picture draws the vocabulary every later slide uses. Open, run, read, close. A connection is a limited thing: remember the orange bar. Everything from here on is about making the orange bar short and the middle part cheap.
+ Same red for the connection on every later slide. The blue strip is your code: touched at the very start (you call) and at the very end (you get the result). In between, ODX does the work.
+ The rack of four is a connection pool: a small, fixed number of ready connections. A call takes one and gives it back.
-
-
- 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.
- At compile time the generator writes the row reader you would write by hand and hands it to the existing selector overload, so the code you write does not change. A hand-written selector and a generated one take the same path.
- Where it cannot generate, for example a call inside a generic method, the runtime map still runs, compiled once per result shape and cached. One property in the project file turns the generator off.
+ The fastest possible code is what an expert would type by hand: column positions and types fixed in the code, nothing looked up, compared or converted while it runs. The build writes that for you from your model, and hands it to the same path a hand-written selector takes. You write nothing, and the code you write does not change.
+ How it fits: a generated Map<T>() is the library's ordinary Map(RowMap<T>) with a row reader written at build time. An interceptor passes the map; Core runs the command and its one read loop; the loop calls the row reader once per row. Terminals, result-set handling, row-error reporting and pooling are Core's, shared with the hand-written selector. One loop to maintain, the same behaviour for every terminal.
+ Measured, read through its own method with an identical hand-written copy as the control: generated equals hand-written, inside the spread between two identical hand-written copies. Against a real database read, which costs microseconds, a few nanoseconds of mapping disappear.
+ Annotations. A model whose members carry the column attributes is read at fixed positions, the same as hand-written. A model without annotations pays a small check per result set: the count and names of the columns are compared once per query, about 1 ns per column. Annotate the model and the check is skipped. This was accepted for 11.0; the cost is inferred from width scaling and the code, not measured alone.
+ Where it does not generate (a call inside a generic method, a single-value model), a runtime map is built once per shape and cached; one project property turns the generator off; C# 12 or later is required. All of that is appendix A4, not on this slide.
-
- 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 40.15 µs
+
ODX Map<T>() 40.26 µs
+
Dapper.AOT [pending]
+
Dapper 170.60 µs
-
-
-
-
[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.
+
+
+
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.
- The top numbers are the best case: a synthetic reader with no database in the way. Then the same query on SQL Server and SQLite. The grey part is a plain loop reading every value: the database’s and the provider’s time, the same for every library. What sits on top is each library’s own work. The error margins are on the benchmark page.
- If your queries are slow because of the database, no mapping library changes that. Where the generator cannot see a type, the runtime map is the fallback. Dapper.AOT was run through its intercepted path, as it is meant to be used.
+ 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 ODX is ahead too, by less; that is the next slide.
-
- 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.
-
- New RowMap<T> at the call site
- 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, 22.91 ms Each method's extra time on top
+
+
+
ODX level with hand-written. Ahead of Dapper.AOT and Dapper.
+
Memory: Dapper allocates 29% more than ODX.
+
- That speed is for a map built once. In daily use the fast path is a query declared once, as a value.
- The SQL and the Map<Post>() are declared once, with no connection. Where the query runs, you bind the source and the values with Using and AddParam, then pick the terminal.
- The mapping from the result's column names and types to Post is compiled once and cached. An inline .Map<Post>() is built once per result shape and cached. A RowMap<T> written at the call site is built again on every call (the 870 µs bar), so declare one for anything that runs more than occasionally. 0.19 to 0.87 ms covers 1 to 20 columns, for the runtime map.
+ "Is that a real database?" Yes: SQL Server LocalDB. If the database is slow, no library fixes that. What a library controls is the thin coloured tip on top, and ODX's is as thin as hand-written. The con, said plainly: the gain is small when the query itself is slow.
+ How to read it: the grey part is plain ADO.NET building the same objects (the database's and the provider's time, the same for every library); each coloured tip is that method's time minus the grey. All from one run of the benchmark matrix, one row type, 10,000 rows of 20 columns.
+ Dapper.AOT, honestly: on a synthetic reader generated ODX beats it on mapping; on a real database ODX is ahead too, by less (SQL Server: 0.35 ms of 23 ms; SQLite: about 2 ms). SQLite shows the same shape and is appendix A15.
+
+
+
+ Why the orange bar matters
+ A fixed number of connections. The same requests. Only the hold time differs.
+
+
+
+
+
+
+ Say it first: this is a model, not a measurement. Same traffic, same four connections. Hold each one longer and a line forms.
+ Four connections serve requests that arrive at the same steady rate; only the hold time differs. With the short hold the queue stays empty; with the long hold a queue builds up. Requests wait for a free connection. A connection pool has a maximum size, and a database a limited number of workers.
+ Limits, said aloud once: queueing at scale was not measured, and neither was the gain from releasing a thread.
-
-
- 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
- 1 exactly
- 2 ignoring case
-
- 3 ignoring 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.
+
- AddParam takes the name from the argument: a variable or a chain of members such as search.Author. A literal or any other expression needs a name you write yourself.
- For a stored procedure the name is settled when the command runs: the provider reports the real parameter names, and the argument is matched exactly, then ignoring case, then ignoring case and underscores. Names are read once per factory and procedure, and again after a call that cannot be built or that the database rejects, so register the factory once.
+ It opens at the last moment and closes at the first. If you hand it your own connection, it leaves it as it found it. The rule is one sentence: the command closes only what it opened.
+ Scene 1: from a factory, the command creates the connection, opens it if needed, runs the call, closes it and disposes it; a pool's connection is given back. The connection is opened late, and the rule holds when the call throws. Scene 2: a connection that was already open stays open, still yours.
+ The closed-connection scene (opened for the call, closed again, never disposed) and the failure scene are appendix A7, with the code.
-
- 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
-Post row 0
-
-int Id
-int Id ✓
-1 row 1
-
-int Id
-int Id ✓
-2 row 2
-
-int Id
-int Id ✗
-null
-ValueMappingException
-Post, row 2
-int? gives null
-Later result sets: read through
-result set 1 result set 2
-an error
-
-ODX keeps reading
-✗
-set 1: read
-thrown, not lost
-First set only
-.SingleResult()
-result set 1 result set 2
-not read
-
-stop
-stops after set 1
-set 2: not read
-Declarations are hard rules
-[Column("id", Order = 0)] Id read as declared ✓
-[Column("title", Order = 1)] Title read as declared ✓
-[NotMapped] Slug no column is read keeps "unset"
-[Column("title", Order = 1)] Title declared, but missing throws ValueMappingException
-
+
+ Default
+ worker connection
+ Read()
+
+ free while it is awaited
+
+
+
+
+ Option
+ worker connection
+ .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 server busy server
+
+
+ working
+ waiting, holding the worker
+ free to serve others
+ in line for a free worker
+
+
Most rows are already there. Gaps are rare.
+
+
+
Default Shortest hold on the connection. A worker pauses during a rare gap.
+
Option, one word per call No worker ever pauses. Under load the connection can be held longer.
- If the type says int, it is an int. A null into a member the C# type declares non-nullable throws ValueMappingException, naming the model and the 0-based row; declare string? or int? to get null.
- Version 10 returned the rows and lost a failure in a later statement. Version 11 reads through later result sets and throws it. Caution from the docs: a later failure can follow a write that already committed, so a caller that retries can repeat the write. SingleResult reads only the first set.
+ Step 0: this is one call, seen from outside. Open, the database works, rows come back in bursts with short gaps. The outside world does not change between the lanes; that is the point.
+ Steps 1 and 2: the top lane is what ODX does unless you say otherwise; the bottom lane is the option. Opening the connection and running the command are awaited in both, so the worker is free then. Only the row reads differ, and both lanes finish together (the measured basis for "same" is the previous slide's pair 2). A "worker" is a thread.
+ Step 3: this is the whole difference. In a gap the next rows are still on the way. The default keeps its worker for a moment; the option gives it away and picks up again when rows arrive.
+ Step 4: most rows are already there; gaps are rare. On Map<T>(), 4 of 10,001 reads did not complete at once. Keep that figure in your head, not on screen.
+ Step 5: flip from a calm server to a busy one. When every worker is busy, coming back means queueing, and the connection waits with you. The default lane does not move. Say plainly that the gain from freeing the worker was not measured; do not claim a throughput gain for the option.
+ Step 6: the verdict. Default: shortest hold on the connection, and a worker pauses during rare gaps. Option, one word per call: no worker ever pauses; under load the connection can be held longer. Only now the code names appear: Read() and .AsyncReads().
+ Honesty: this is a picture with no numbers, not to scale; say so once, do not print it. The measured sizes are on the previous slide. Memory, cancellation, large values and Map(Func) are appendix A14; the busy thread pool close-up is A13.
-
- 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.
+ Default The option
+
+
+
-// 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
-
-
-disposed back to the pool
-Your connection, closed
-✗ fails
-
-
-closed again never disposed
-Your connection, open
-✗ fails
-
-
-stays open still yours
-A SQL error, a timeout or a cancel: the connection is put back, then the exception reaches you.
-
-
-
-
- The rule is one sentence: the command closes only what it opened. A connection you hand it is yours; it is opened if it was closed, closed again if the command opened it, and never disposed.
- From a factory, the command creates the connection, opens it if needed and disposes it. The connection is opened late, and the rule holds when the call throws.
-
-
+
Real SQL Server, slow link
+
+
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
+
+
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
- ODX opens late and closes early. Here is why that is worth so much care.
- An illustrative model, not a measurement: four connections, the same requests arriving at the same steady rate, and only the hold time differs. With the short hold the queue stays empty; with the long hold, a queue builds up.
- 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.
+ Say it: two times out of three you cannot tell them apart. In the third, the default wins by a wide margin. That is why it is the default, and the other is one word away for the teams that need it. This answers "why is the default not async".
+ Pair 1: a synthetic reader with every row ready, 20 columns, 1,000 rows. Pair 2: real SQL Server over a simulated 5 ms, 100 Mbit link; the link sets the time. Pair 3: a synthetic reader with a 20 µs wait every 100 rows while the thread pool is busy (8 queued work items); one run per case, so say that. If that is too thin to show a boss, show pairs 1 and 2 and describe the third in words; appendix A14 has all four conditions.
+ Pros and cons, said plainly. Default: the shortest hold on the connection, and a worker pauses briefly during the rare gap. The option: no worker ever pauses, but under load the connection can be held longer and memory can be higher. The gain from freeing the worker was not measured. Most reads complete at once; on Map<T>(), 4 of 10,001 did not.
-
-
-
- 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]
+
+ Two things are scarce in a request: the connection and the memory. The orange bar was the connection; this is the memory.
+ The usual stack copies each row several times: entities into DTOs, a list for the serializer. Two sets of row objects and two lists. ODX reads each row once into pooled arrays that later requests reuse. Less copying means less memory and less clean-up work for the runtime.
+ Last step: the whole request, ending in JSON, with the pooled buffer (one copy) against an exactly sized array (copies). Time and memory per request.
+ The con, said plainly: you must hand the memory back when you are done. In a web framework the framework does that for you (appendix A8). The full journey of a result is A9; the loop that reads while it fills is A10.
+
+
+
+
+ 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.
+
+
+
+
+ If you need one row of three million, tell the server to stop sending. One opt-in tells it: CancelOnEarlyStop().
+ Say the limits aloud: the wire picture is illustrative, not to scale, and the 0.4 bar is drawn at a minimum width. SQL Server sends every row of a result, the ones you did not ask for included. The opt-in cancels the command when a terminal stops with rows left, so the rest are discarded: 202 ms down to 0.4 ms for the first row of 3 million, on SQL Server LocalDB.
+ When it does not help: a TOP 1 or a key lookup, about 80 µs either way. Do not use it with a batch whose later statements matter, with BEGIN TRAN or XACT_ABORT in the SQL (not detected), or with a transaction, an output parameter or an ambient TransactionScope (refused with InvalidOperationException). Verified on SQL Server LocalDB, and on SQLite for usability only. The snippet and the limits are appendix A12; streaming is A11.
+
+
+
+
+ Wrong data fails loudly
+ You find out on that row, not three screens later.
+
+
+
+null into a non-nullable member
+Post row 0
+
+int Id
+int Id ✓
+1 row 1
+
+int Id
+int Id ✓
+2 row 2
+
+int Id
+int Id ✗
+null
+ValueMappingException
+Post, row 2
+int? gives null
+Later result sets: read through
+result set 1 result 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.
+
+
+
+
+ If the data does not fit what you declared, you find out on that row, with the row number. ODX never hands you a silently wrong value or hides an error.
+ Scene 1: a null into a member the C# type declares non-nullable throws ValueMappingException, naming the model and the 0-based row; declare int? or string? to get null. Scene 2: version 10 returned the rows and lost a failure in a later statement; version 11 reads through later result sets and throws it. Caution from the docs: a later failure can follow a write that already committed, so a caller that retries can repeat the write.
+ The model code, SingleResult (reads only the first set) and the declared-column rules are appendix A6.
+
+
+
+
+ Less code. Hand-written speed. Calm under load.
+
+
+
As fast as hand-written
+
+
+
+
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
+
+ Less code, hand-written speed, and it is careful with the two things a server runs out of: connections and memory. Now, questions.
+ The next key press opens the Go deeper menu: the map of every question this deck did not answer on screen. Packages and target frameworks are in appendix A19.
+ Version 11 is not binary compatible with 10.x, so rebuild every consumer; the migration page lists each removed member with its replacement.
+
+
+
+
+ Go deeper
+ Each card answers a question. Pick one.
+
+
In this deck, in the order of the slides they back up
+
A1 The 22 lines The plain ADO.NET code in full
+
A2 Setup once, code per call ODX, EF Core and Dapper side by side
+
A3 How little code Four tasks, four libraries
+
A4 Generator details When it does not generate; opting out
+
A5 A query as a value Define once, bind where it runs
+
A6 Parameters and mapping rules Names, stored procedures, declared columns
+
A7 Connection ownership Closed, open and failing connections
+
A8 Buffered results In a controller, no service layer
+
A9 The journey of a result From the query to the end of the request
+
A10 While it fills Reading chunks as they are published
+
A11 Streaming, safely Row by row; the stall timeout
+
A12 Stop early: the details The snippet, when it does not help, the limits
+
A13 Busy thread pool Close-up of the queue after a gap
+
A14 Async reads in full Four conditions, memory, a 100 MB value
+
A15 How the numbers were made Method; where ODX is not faster; SQLite
+
A16 Cost per column What one more column costs
+
A17 Pooling Rows go into rented arrays and back
+
A18 Clearing pooled arrays What is cleared, and why
+
A19 Packages and pipelines Packages, frameworks, channels, dataflow
+
In the docs
+
Docs article Mapping rows Renamed columns, records and constructors, and null policy.
+
Docs article Shaping rows When the row you want is not the row the query returns: recipes, no new API.
+
Docs article Expressive commands Factory or connection, defining a query once, parameters and terminals.
+
Docs article Coming from Dapper The steps side by side, and who handles the connection.
+
Docs article With minimal APIs The same command factory in an endpoint, no service layer.
+
+
+ This is the map of the questions. Ask the room which one they want and follow it; every card is one click from where the question came up. The arrow keys carry on through the appendix in order. If a question came up earlier and was parked, this is where it is answered.
+ Five cards lead to articles in the docs instead of slides.
+
+
+
+ ← 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
+
+
+
+ This is the real plain ADO.NET version from the docs, blank lines dropped: 22 lines to read one author's posts into a list.
+ Most of it is plumbing, not the query. The usual way to avoid it is an ORM, which writes the query as LINQ. ODX takes the other road: you keep writing SQL.
+
+
+
+ ← 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
+
once per call
+
+
+
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.
+
+ You may be thinking that an ORM such as EF Core is short too. It is, per call; the setup is just written somewhere else.
+ EF Core does need setup. There is a context class, a set for the model, configuration and registration, and writes also need a save call. After that, a query is short and clean, and the table on the bonus slide How little code shows it.
+ ODX sets up differently, because it is not an ORM. There is no change tracking and no SaveChanges; you write the SQL. You define the query once, as a static value, with no context at all. Where it runs, the code is a few lines: bind the connection factory and the values, then pick the terminal.
+ Counts: 5 lines for the sample context, 2 for the static query. The EF Core configuration and registration are not in the samples, so they have no number here.
+
+
+
+ ← 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).
+ ODX Dapper EF Core ADO.NET
+
+ 2. Filter in SQL, project in C#, async stream
+ 3. One author's rows in memory, then LINQ
+ 4. A stored procedure, two parameters
+ 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.
+
+ All four versions of each task are compiled in the samples project, and the samples check that they return the same rows.
+ Be upfront: EF Core is shorter than ODX in the first three tasks, by 1, 2 and 2 lines, once its DbContext exists. ODX is shorter in task 4, and equal to Dapper in task 3. Where ODX saves is the plumbing: no connection to create, and no column copying.
+
+
+
+
+ ← Go deeper
+ Generator details
+ What the build does when it can, and when it cannot.
+
+
Where it cannot generate A 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.
+
Requires C# 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.
+
+
+ Where the main slide shows only the path that is taken, this one lists the edges. A generic method hides the type from the generator, so it falls back to the runtime map: compiled once per result shape and cached, the same map the version 10 successor always used. A model that is a single value (such as an int) is not generated; the runtime map handles it.
+ The check on unannotated models: per result set the count and names of the columns are compared, about 1 ns per column per query (a few nanoseconds at 10 columns, under twenty at 20 columns, for a one-row query). Annotated models have none. The cost is inferred from width scaling and the code, not measured alone.
+
+
+
+ ← 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.
+
+ New RowMap<T> at the call site
+ Building the map: 190 to 870 µs for 1 to 20 columns. With the generator, at build time, except in a generic method.
+
+ That speed is for a map built once. In daily use the fast path is a query declared once, as a value.
+ The SQL and the Map<Post>() are declared once, with no connection. Where the query runs, you bind the source and the values with Using and AddParam, then pick the terminal.
+ The mapping from the result's column names and types to Post is compiled once and cached. An inline .Map<Post>() is built once per result shape and cached. A RowMap<T> written at the call site is built again on every call (the 870 µs bar), so declare one for anything that runs more than occasionally. 0.19 to 0.87 ms covers 1 to 20 columns, for the runtime map.
+
+
+
+ ← 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
+ 1 exactly
+ 2 ignoring case
+
+ 3 ignoring 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.
+
+
+
+ AddParam takes the name from the argument: a variable or a chain of members such as search.Author. A literal or any other expression needs a name you write yourself.
+ For a stored procedure the name is settled when the command runs: the provider reports the real parameter names, and the argument is matched exactly, then ignoring case, then ignoring case and underscores. Names are read once per factory and procedure, and again after a call that cannot be built or that the database rejects, so register the factory once.
+
+
+
+ ← 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
+Post row 0
+
+int Id
+int Id ✓
+1 row 1
+
+int Id
+int Id ✓
+2 row 2
+
+int Id
+int Id ✗
+null
+ValueMappingException
+Post, row 2
+int? gives null
+Later result sets: read through
+result set 1 result set 2
+an error
+
+ODX keeps reading
+✗
+set 1: read
+thrown, not lost
+First set only
+.SingleResult()
+result set 1 result set 2
+not read
+
+stop
+stops after set 1
+set 2: not read
+Declarations are hard rules
+[Column("id", Order = 0)] Id read as declared ✓
+[Column("title", Order = 1)] Title read as declared ✓
+[NotMapped] Slug no column is read keeps "unset"
+[Column("title", Order = 1)] Title declared, but missing throws ValueMappingException
+
+
+
- Two things are scarce in a request: the connection and the memory. The connection first, now the memory.
- The usual stack copies entities into DTOs and hands a list to the serializer. Two sets of row objects and two lists, against one set in pooled arrays that later requests reuse.
+ If the type says int, it is an int. A null into a member the C# type declares non-nullable throws ValueMappingException, naming the model and the 0-based row; declare string? or int? to get null.
+ Version 10 returned the rows and lost a failure in a later statement. Version 11 reads through later result sets and throws it. Caution from the docs: a later failure can follow a write that already committed, so a caller that retries can repeat the write. SingleResult reads only the first set.
+
+ ← 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
+
+
+disposed back to the pool
+Your connection, closed
+✗ fails
+
+
+closed again never disposed
+Your connection, open
+✗ fails
+
+
+stays open still yours
+A SQL error, a timeout or a cancel: the connection is put back, then the exception reaches you.
+
+
+
+
+ The rule is one sentence: the command closes only what it opened. A connection you hand it is yours; it is opened if it was closed, closed again if the command opened it, and never disposed.
+ From a factory, the command creates the connection, opens it if needed and disposes it. The connection is opened late, and the rule holds when the call throws.
+
+
+
+ ← 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.
-
+
@@ -1240,8 +1801,8 @@ Buffered results, no service layer
Keep two clocks apart: how long the connection is held, and the total time. The buffer closes the connection when the read ends, however slowly you read it, so it holds the connection about as long as ToArrayAsync; the total differs because the rows stay pooled and are released at dispose. It has no final copy, which is why it suits handing rows to a controller.
-
-
+
+ ← 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
ToPooledBuffer here: Items, after the last row DB controller serialize JSON dispose: back to the pool connection held total time, until you are done with the rows database Read : all rows into pooled chunks in a background task; the call returns at once; connection released at last rowHand over : no copy and no extra array, the controller reads the chunks themselvesRespond : serializes the chunksEnd : the buffer is disposed after the response; chunks go back to the pool, reused next
no copy no extra array arrays 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]
Follow one result from the query to the end of the request. With ToArrayAsync the rows go into pooled chunks, the connection is released at the last row, and the rows are copied once into an exactly sized array (for class rows the references are copied, not the objects). The chunks go back to the pool, the controller serializes the array, and the garbage collector takes it afterwards.
With ToPooledBuffer the call returns at once and the rows are read into pooled chunks in a background task; connection is released at the last row. Here the controller waits for Items, all rows, then serializes straight from the chunks: no copy, no extra array. The next slide reads them while it fills. When the buffer is disposed after the response, the chunks return to the pool and the next request reuses them.
- Keep two clocks apart, the strips under each flow: how long the connection is held, which ends when the read ends in both cases, and the total, which runs until you are done with the rows. That is why the buffer suits a controller while ToArrayAsync stays the fastest way to a finished array you keep. The animation shows the order of events, not their duration; the end-to-end numbers come from an rc.16 benchmark.
+ Keep two clocks apart, the strips under each flow: how long the connection is held, which ends when the read ends in both cases, and the total, which runs until you are done with the rows. That is why the buffer suits a controller while ToArrayAsync stays the fastest way to a finished array you keep. The animation shows the order of events, not their duration; the end-to-end numbers come from the published benchmark.
-
-
+
+ ← 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 chunk DB controller serialize JSON dispose: back to the pool connection held total time, until you are done with the rows database Read : all rows into pooled chunks in the background; connection released at last rowEnumerate : the controller takes each chunk as it is published, never a half-filled oneRespond : serializes each chunkEnd : the buffer is disposed; chunks go back to the poolawait buffer.Items Items: waits for all rows DB controller serialize JSON dispose: back to the pool connection held total time, until you are done with the rows database Read : all rows into pooled chunks in a background task; the call returns at once; connection released at last rowHand over : no copy and no extra array, the controller reads the chunks themselvesRespond : serializes the chunksEnd : the buffer is disposed after the response; chunks go back 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]
AsAsyncEnumerable() streams the buffer’s rows as each chunk is published: the controller can start on the first chunk while the read goes on, whole chunks only, never a half-filled one. Items still waits for all rows. The connection is released at the last row either way, and dispose returns the chunks to the pool.
-
-
-
- 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
One more choice decides how long the connection is held: how each row is read.
- An illustration, not a measurement. The greedy read keeps its thread at every network wait, finishes, closes the connection, and only then do others get a turn. The polite read gives the thread back at every wait, and then waits in line for a free thread while the connection stays open.
+ An illustration, not a measurement. The default read keeps its thread at every network wait, finishes, closes the connection, and only then do others get a turn. The option gives the thread back at every wait, and then waits in line for a free thread while the connection stays open.
The measured size of that gap is on the next slide, Async done right: 0.28 ms against 2.2 ms with a busy pool and a wait every 100 rows. Most ReadAsync calls complete at once, so the line forms only at the waits.
-
-
-
+
+ ← 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
-
- Package Use it for
- Open.Database.Extensions.Core Everything, provider-agnostic
- Open.Database.Extensions.MSSqlClient SqlConnectionFactory, SQL Server
- Open.Database.Extensions.Channel Reading into channels
- Open.Database.Extensions.Dataflow Reading 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
-
- One package covers most applications: Core is provider-agnostic. The others add SQL Server helpers, channels and dataflow blocks. Version 11 is not binary compatible with 10.x, so rebuild every consumer.
- The migration page lists each removed member with its replacement. Everything here is open source under the MIT license, and the documentation site has the API reference.
-
-
-
-
- Go deeper
- Pick a topic.
-
-
In this deck
-
In this deck How little code Lines per method: four tasks, four libraries.
-
In this deck Cost per column What one more column costs, from 1 to 20 columns.
-
In this deck Pooling Rows go into rented arrays, and the arrays go back.
-
In this deck Clearing pooled arrays What is cleared when arrays go back, and why.
-
In this deck Pipelines Channels and Dataflow over Map<T>().
-
In the docs
-
Docs article Mapping rows Renamed columns, records and constructors, and null policy.
-
Docs article Shaping rows When the row you want is not the row the query returns: recipes, no new API.
-
Docs article Expressive commands Factory or connection, defining a query once, parameters and terminals.
-
Docs article Coming from Dapper The steps side by side, and who handles the connection.
-
Docs article With minimal APIs The 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: 24.77 ms Each method's extra time
+
+
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 227 KB
+
Dapper 548 KB
+
+
- That is the main talk. These are the things we did not cover; each card goes either to a bonus slide in this deck (five of them) or to an article in the docs (five).
- Ask the room which one they want and follow it. The arrow keys carry on through the bonus slides in order.
-
-
-
-
-
- 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
- ODX Dapper EF Core ADO.NET
-
- 2. Filter in SQL, project in C#, async stream
- 3. One author's rows in memory, then LINQ
- 4. A stored procedure, two parameters
- 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.
-
- All four versions of each task are compiled in the samples project, and the samples check that they return the same rows.
- Be upfront: EF Core is shorter than ODX in the first three tasks, by 1, 2 and 2 lines, once its DbContext exists. ODX is shorter in task 4, and equal to Dapper in task 3. Where ODX saves is the plumbing: no connection to create, and no column copying.
+ The SQLite chart reads like the SQL Server one: the grey part is plain ADO.NET building the same objects, each tip is that method's time minus the grey. On SQLite, Dapper.AOT adds about 2 ms; ODX and hand-written sit at the floor, within noise.
+ The memory bars are the synthetic run behind the How fast slide: ODX, hand-written and Dapper.AOT allocate the same; Dapper allocates more.
-
-
-
+
+ ← Go deeper
Cost per column
Nanoseconds for one more cell. Synthetic reader, 1,000 rows, 1 to 20 columns.
- ← Go deeper
1 column time for 1,000 rows, µs 20 columns cost 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 5.85
43.66 1.99 ns
+
+
ODX Map<T>() 5.84
42.85 1.95 ns
+
+
object[] rows 11.26
163.03 7.99 ns
+
+
Dapper Query<T> 15.84
163.24 7.76 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 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.
Every approach grows in a nearly straight line, so each has a cost per cell. That is why the lead over Dapper grows with the width. For a narrow result the choice hardly shows.
This run is separate from the library comparison, so the 20-column figure here differs a little from the whole-call figure there. Where the generator cannot see the type, the runtime map is used instead.
-
-
-
- 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
+
+ Package Use it for
+ Open.Database.Extensions.Core Everything, provider-agnostic
+ Open.Database.Extensions.MSSqlClient SqlConnectionFactory, SQL Server
+ Open.Database.Extensions.Channel Reading into channels
+ Open.Database.Extensions.Dataflow Reading 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
+
+ One package covers most applications: Core is provider-agnostic. The others add SQL Server helpers, channels and dataflow blocks. Version 11 is not binary compatible with 10.x, so rebuild every consumer.
+ The migration page lists each removed member with its replacement. Everything here is open source under the MIT license, and the documentation site has the API reference.
+
+
+
+ ← 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);