From 9ae3ca5957599c5ae6e154acd05d1789bae1f834 Mon Sep 17 00:00:00 2001 From: electricessence <5899455+electricessence@users.noreply.github.com> Date: Wed, 2 Dec 2026 08:58:00 -0800 Subject: [PATCH] Version 11.0.0-rc.17 The release-candidate suffix moves from rc.16 to rc.17, in the build properties and at the top of the release notes. The release notes and the migration page are brought in line with what changed since rc.16: - The long note on removed parameter directions is split into what was removed, what to use instead, and the one call that became ambiguous. - A note for an options object whose own cancellation token is already canceled when AsSourceBlock is called. - The migration page's pooling section says that a collecting terminal clears value rows when no pool is offered, points to the generated readers, and shows the DbQuery example as a stored field in a class. Co-Authored-By: Claude Sonnet 5.5 --- Source/Directory.Build.props | 2 +- docsite/articles/release-notes.md | 8 ++++++-- docsite/articles/whats-new-11.md | 23 +++++++++++++++++------ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Source/Directory.Build.props b/Source/Directory.Build.props index 99bb7d19..e7088777 100644 --- a/Source/Directory.Build.props +++ b/Source/Directory.Build.props @@ -6,7 +6,7 @@ 11.0.0 debug - rc.16 + rc.17 diff --git a/docsite/articles/release-notes.md b/docsite/articles/release-notes.md index 7bce72c1..1b7cbe58 100644 --- a/docsite/articles/release-notes.md +++ b/docsite/articles/release-notes.md @@ -1,6 +1,6 @@ # Release notes -Version 11 is `11.0.0-rc.16`. For moving a 10.x codebase, read [Coming from earlier versions](whats-new-11.md) first; this page lists each release. +Version 11 is `11.0.0-rc.17`. For moving a 10.x codebase, read [Coming from earlier versions](whats-new-11.md) first; this page lists each release. ## Version 11 release candidates @@ -11,7 +11,9 @@ Version 11 is `11.0.0-rc.16`. For moving a 10.x codebase, read [Coming from earl - **Fixed: a cancel during `AsAsyncEnumerable(pool)`.** On a `DbDataReader`, `AsAsyncEnumerable(arrayPool)` with a pool (the form that reads every column) did not pass its token to `ReadAsync`, so a read the provider cancelled threw out of the enumeration. It now ends the enumeration quietly with the rows already yielded, as the other forms do. - **Fixed: `CreateCommand` on a `SqlTransaction` that has no connection throws `InvalidOperationException`.** The SQL Server package threw `ArgumentNullException` named `connection`; both packages now throw `InvalidOperationException`, with a message that says the cause and the fix. `CreateTextCommand` and `CreateStoredProcedureCommand` follow. - **Fixed: a failed read through `ToChannel` or `ToChannelReader` was also raised as an unobserved task exception.** The failure reached the channel, as documented, but the read's task was dropped by the forms that do not return the count, so `TaskScheduler.UnobservedTaskException` fired when the task was collected. The task's fault is now read, so nothing is raised; the count you ask for with `ToChannel(out Task readCount)` still throws when awaited. -- **Removed: parameter directions on the fluent chain.** `AddParam` and `AddParamIf` no longer take a `ParameterDirection`; `AddReturnParam` is gone, and `AddParam(name, direction)`, `AddParamIf(condition, name, direction)`, `AddParam(name, type)` and `AddParamIf(condition, name, type)` are now compile errors that say what to do instead. The forms that took a direction after the value, `AddParam(name, value, ParameterDirection)` and `AddParam(name, value, type, direction)` (the SQL Server forms with a database type and a direction too), fail to compile with the compiler's own argument error, without a message of their own: use the raw `AddParameter` inside `ExecuteAsync(command => ...)`, or read the output with `ExecuteOutputAsync`. A parameter on the chain is an input. To set a direction, use `ExecuteAsync(command => ...)` with the raw `AddParameter`, `AddParameterType` and `AddReturnParameter` extensions. Calls that never passed a direction compile unchanged, with one exception: a constant zero of type `byte` on the SQL Server command, `AddParam(name, (byte)0)`, used to bind silently to the direction overload and is now an ambiguous-call error (CS0121); pass a variable, or give the database type, `AddParam(name, value, SqlDbType.TinyInt)`. `Param` has no `direction` constructor parameter and no `Direction` property. +- **Removed: parameter directions on the fluent chain.** `AddParam` and `AddParamIf` no longer take a `ParameterDirection`; `AddReturnParam` is gone, and `AddParam(name, direction)`, `AddParamIf(condition, name, direction)`, `AddParam(name, type)` and `AddParamIf(condition, name, type)` are now compile errors that say what to do instead. The forms that took a direction after the value, `AddParam(name, value, ParameterDirection)` and `AddParam(name, value, type, direction)` (the SQL Server forms with a database type and a direction too), fail to compile with the compiler's own argument error, without a message of their own. A parameter on the chain is an input. `Param` has no `direction` constructor parameter and no `Direction` property. +- **To set a direction, or read an output:** use `ExecuteAsync(command => ...)` with the raw `AddParameter`, `AddParameterType` and `AddReturnParameter` extensions, or read the output with `ExecuteOutputAsync`. +- **Changed: `AddParam(name, (byte)0)` on the SQL Server command is an ambiguous call.** A constant zero of type `byte` used to bind silently to the direction overload; it now fails to compile (CS0121). Pass a variable, or give the database type, `AddParam(name, value, SqlDbType.TinyInt)`. Calls that never passed a direction compile unchanged. - **Read output parameters: `ExecuteOutputAsync()`.** It maps a command's output parameters and return code into a model by name, with the `Map()` rules; `ExecuteOutputAsync(name)` reads one value, and `CaptureOutput(out DbCapture value, name)` captures one; a name finds its parameter the way `AddParam`'s name does (exactly, else ignoring case, else ignoring case and underscores, else without a common prefix such as `p_`), so `"totalCount"` finds `@total_count`. A `decimal` declares its SQL type: `[Column(TypeName = "decimal(p,s)")]` on a member, or `ExecuteOutputAsync(name, precision, scale)` (`ExecuteOutputDecimalAsync`) for one value. See [Output parameters](expressive-commands.md#output-parameters). - **New: captures, output parameters beside rows.** `CaptureOutput` (a model, one value, or a `decimal` with its precision and scale), `CaptureOutputDecimal` and `CaptureReturn` on an expressive command, a mapped query and its `Skip` and `Take` views give a `DbCapture` as an `out` argument; the async terminal fills it, and a stream fills it when its loop ends, a `break` included. A capture runs once and needs an async terminal; a query's run fills the captures its command has when the run starts, including one added after `Map`. Misuse throws at the call, except that the return code of a command that is not a stored procedure is refused when the run starts: `NotSupportedException` on a query that does not read from an expressive command, `InvalidOperationException` otherwise. A command whose type re-implements `IExecuteReader` is refused too, as `NotSupportedException` on a query capture and `InvalidOperationException` when a command capture runs. See [Output parameters beside rows](expressive-commands.md#output-parameters-beside-rows). - **New: definitions declare and read outputs.** `DbNonQuery.Procedure(name).Output()` declares that a write reads its output parameters and return code into a model; `Output(name)`, `Output(name, precision, scale)` and `OutputDecimal(name, precision, scale)` read one value. A bound call reads it with `ExecuteOutputAsync()`, and `ExecuteReturnAsync()` reads a stored procedure's return code. The model is checked when the definition is declared; `Params()` combines with `Output` in either order. See [Output parameters](expressive-commands.md#output-parameters). @@ -20,6 +22,8 @@ Version 11 is `11.0.0-rc.16`. For moving a 10.x codebase, read [Coming from earl - **Changed: the collecting terminals clear their value rows when no pool is offered.** `ToList`, `ToArray`, `ToImmutableArray`, `ToHashSet` and the dictionaries, asynchronous and synchronous, on a view or on a `DbDataReader`, copy their rows out and never show their pooled arrays, so they hide their pooling: a query that does not call `UsePool` now always clears the used rows of those arrays before they go back, plain value rows included, whatever the `Open.Database.Extensions.ClearPooledArrays` switch says. `UsePool(pool, clearOnReturn)` is followed as before, so `clearOnReturn: false` still keeps the rows. Rows that hold references were always cleared. The buffers and streams are unchanged: their default is still not to clear value rows. A chunk of 128 KB or more is cleared in the background, as before, and the allocation of a call is the same. - **Changed: the synchronous `ToList()` reads into pooled chunks, as `ToListAsync` does.** On a view or a reader it grew a list of its own, and so allocated the growth as well as the result and rented no pooled array; it now reads into the chain of pooled arrays and copies the rows once into a list of exactly their number, so the copy-out clearing above applies to it too. The growth is gone: 100,000 `int` rows allocate about 400 KB instead of about 1.05 MB, and 1,000 rows about 28.8 KB instead of 33.2 KB. - **New: `WithOptions(QueryOptions)` sets the four switches of a mapped query at once.** `QueryOptions` is a flags enum (`None`, `AsyncReads`, `SingleResult`, `CancelOnEarlyStop`, `SequentialAccess`), and `WithOptions(x)` on `MappedQuery` (also after `Skip` or `Take`), `MappedCommand`, `MappedDbQuery` and `MappedDbQuery` is the same query as the calls that set those switches one by one. It sets, it does not add: a switch that is not in the value is off, also one a command chose before `Map` (`SingleResult()`, `AsyncReads()`), so `WithOptions(QueryOptions.None)` turns all of them off. A value with a bit that is no switch throws `ArgumentOutOfRangeException` that names the valid ones. The four methods keep working as before. +- **Changed: several exception messages now say what to do.** A blank command, a command whose type does not match the connection's provider, concurrent use of a single connection, a reader of the wrong type and a transaction without a connection each name the cause and the fix. The messages of a captured `ExecuteReturnAsync` show the typed form of the call (`ExecuteReturnAsync()`), as the uncaptured one does. +- **Changed: `AsSourceBlock` with options whose own `CancellationToken` is already canceled.** The block is created completed, and its pass now ends without running the command; before, it ran the query and stopped at the first row. The block ends canceled either way. A canceled token passed to the call itself still throws `OperationCanceledException` at the call. ### Changes since rc.15 diff --git a/docsite/articles/whats-new-11.md b/docsite/articles/whats-new-11.md index 2ffad3ae..d9b8fe7e 100644 --- a/docsite/articles/whats-new-11.md +++ b/docsite/articles/whats-new-11.md @@ -11,12 +11,21 @@ Packages: use `Open.Database.Extensions.MSSqlClient` (on `Microsoft.Data.SqlClie A query is defined once, mapped, with no connection; the source and the values are given where it runs. There is nothing to migrate: it is new in 11. ```cs -static readonly MappedDbQuery ByAuthor = DbQuery - .Text("select * from posts where author = @author") - .Map(); +using System.Data.Common; -public ValueTask> ByAuthorAsync(int author, CancellationToken cancellationToken) - => ByAuthor.Using(connectionFactory).AddParam(author).ToListAsync(cancellationToken); +public class PostQueries(IDbConnectionFactory connectionFactory) +{ + static readonly MappedDbQuery ByAuthor + = DbQuery.Text("select * from posts where author = @author") + .Map(); + + public ValueTask> ByAuthorAsync( + int author, + CancellationToken cancellationToken) + => ByAuthor.Using(connectionFactory) + .AddParam(author) + .ToListAsync(cancellationToken); +} ``` See [Expressive commands](expressive-commands.md). @@ -29,6 +38,8 @@ Every way of turning rows into objects is `Map()` followed by a terminal. The [!code-csharp[](../samples/Migration.cs#migration_results_after)] +A plain `Map()` on a command, a reader or a `DbQuery` gets a row reader written at build time, which does not apply the runtime map's conversions: see [Generated readers](mapping.md#generated-readers) for the differences and the switch. + | In 10.x | In 11 | |---|---| | `Results()`, `ResultsAsync()`, `ResultsBuffered()` | `.Map().ToListAsync(cancellationToken)` | @@ -139,7 +150,7 @@ See [Parameters](expressive-commands.md#name-a-parameter-from-its-argument). ## Pooling and clearing -Rows that hold references are always cleared before their array goes back to the pool. Rows without references are cleared only when asked: per query with `.UsePool(pool, clearOnReturn)` after `Map`, or for the whole app with the switch `Open.Database.Extensions.ClearPooledArrays`. A chunk of 128 KB or more of rows (rows times row size, value rows included) is cleared off the read path. A read that finds no rows completes `Items` with a shared empty view, which keeps working after the buffer is disposed. See [Pooled buffers and streams](async-buffers.md#pooled-memory). +Rows that hold references are always cleared before their array goes back to the pool. A collecting terminal (`ToList`, `ToArray`, `ToImmutableArray`, `ToHashSet` and the dictionaries) that is offered no pool also clears plain value rows, because it copies its rows out and hides its pooling; `.UsePool(pool, clearOnReturn)` after `Map` is followed as written. For a buffer or a stream, rows without references are cleared only when asked: per query with `.UsePool(pool, clearOnReturn)`, or for the whole app with the switch `Open.Database.Extensions.ClearPooledArrays`. A chunk of 128 KB or more of rows (rows times row size, value rows included) is cleared off the read path. A read that finds no rows completes `Items` with a shared empty view, which keeps working after the buffer is disposed. See [Pooled buffers and streams](async-buffers.md#pooled-memory). ## Transactions and connections