From 19eb1c389272450b16c9137518737b916d0df72a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gro=C3=9F?= Date: Sat, 31 Oct 2026 22:02:24 +0100 Subject: [PATCH 01/13] docs: decision 129, Metalama 2027.0 moves into 2.4.0 2.4.0 must build for every .NET 11 consumer, also one with only SDK 11 installed. On Metalama 2026.1 a web project fails there with LAMA0625, on net10.0 as on net11.0 (KB-060, #275), so the Generators package moves to Metalama 2027.0 in 2.4.0 for both targets, and 2.4.0 is tagged only on a stable 2027.0. A CI lane with only SDK 11 installed joins decision 120's conditions (#281); 2.3.x is the line below the ceiling. #173, #272 and #223 move to the 2.4.0 epic. Replaces decision 120's Metalama timing. Closes #280 Co-Authored-By: Claude Opus 5.5 --- .../0129-metalama-2027-0-moves-into-2-4-0.md | 77 +++++++++++++++++++ design/adr/README.md | 3 +- design/roadmap.md | 20 ++--- 3 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 design/adr/0129-metalama-2027-0-moves-into-2-4-0.md diff --git a/design/adr/0129-metalama-2027-0-moves-into-2-4-0.md b/design/adr/0129-metalama-2027-0-moves-into-2-4-0.md new file mode 100644 index 0000000..426bbe1 --- /dev/null +++ b/design/adr/0129-metalama-2027-0-moves-into-2-4-0.md @@ -0,0 +1,77 @@ +# 0129. Metalama 2027.0 moves into 2.4.0, so a consumer with only the .NET 11 SDK builds + +Date: 2026-10-31 +Status: accepted + +Context: 2026-10-31, issue #280; replaces the timing in +[decision 120](0120-a-net11-0-target-and-documented-floor-raises-join-a-minor.md)'s Metalama paragraph ("2.3 and 2.4 +stay on 2026.1, and 2.5.0 moves both targets to 2027.0"). Decision 120 named the cost of holding 2026.1 on SDK 11 as +LAMA0617, "a warning, falling back to the SDK 10 Razor compiler". The RC3 spike (`spikes/Sdk11Rc3Metalama`, +[KB-060](../knowledge/KB-060-metalama-2026-1-on-the-net-11-sdk.md)) found that the fallback exists only when an SDK 10 +is installed beside SDK 11: without one, a web project with the Generators package fails with LAMA0625 (#275). The +maintainer decided, in these words: "I want a 2.4.0 that compiles at every .NET11-consumer, even when he has only +.NET 11 SDK installed. If this doesn't work with Metalama 2026, then we need to take a straight decision", and +accepted the proposal below the same day. + +## Decision + +**The Generators package moves to Metalama 2027.0 in 2.4.0, for the `net10.0` and `net11.0` assets alike.** Every +other rule of decision 120 stands: one Metalama version for every target, the floor raise documented under its +first rule, and the five conditions of its Metalama paragraph, which are now 2.4.0's. Where decision 120 says 2.5.0 +of the move, read 2.4.0, and where it says the 2.4.x line, read 2.3.x. + +**2.4.0 is tagged only on a stable Metalama 2027.0.** A stable package does not depend on a prerelease (NU5104, +an error under this repository's warnings as errors), so 2.4.0's date is Metalama's: 2027.0 is planned for +2027-01-01 in Metalama's internal documents (#173), with no public date on 2026-10-31. A fix a consumer needs before +then ships as a 2.3.x patch. + +**One condition is added: a build with only SDK 11 installed.** CI and the consumer smoke test get a lane whose +.NET installation holds SDK 11 and nothing else, with a web consumer (`Microsoft.NET.Sdk.Web`) on the packages, +because that is the case Metalama 2026.1 fails and the one a machine with SDK 10 beside it never shows. It runs on +the general availability SDK before the tag (#281). + +**2.3.x is the line below the ceiling.** A project that needs Metalama 2026 stays on 2.3.x. On a machine with only +SDK 11, its web projects need SDK 10 installed beside SDK 11, or a direct `Metalama.Framework` 2027 reference beside +the 2.3.x packages, which weaves (KB-060, decision 120); #275 says so, and 2.4.0's changelog names both. + +Refused: + +- **Staying on 2026.1 in 2.4.0 and documenting SDK 10 beside SDK 11.** It fails the requirement, on `net10.0` as on + `net11.0`: the Razor compiler is the SDK's, whatever the target (KB-060). +- **A 2.4.0 without `net11.0`, on 2026.1.** The same: a `net10.0` web project fails on SDK 11 alone. +- **A 2.4.0 on 2027.0-preview.** A stable package on a prerelease dependency (above). +- **Waiting for a 2026.1 patch that supports SDK 11's Roslyn.** Not in this repository's hands, and 2026.1.31 + (compiler 2026.1.21) still fails. + +## Evidence + +[KB-060](../knowledge/KB-060-metalama-2026-1-on-the-net-11-sdk.md), measured 2026-10-31 on macOS arm64 with the +published 2.3.1 packages: + +| Web project | Metalama 2026.1 | Metalama 2027.0.5-preview | +|---|---|---| +| SDK 11 RC3 alone, `net11.0` | LAMA0625 (2026.1.31 too) | builds | +| SDK 11 RC3 alone, `net10.0` | LAMA0625 | builds | +| SDK 11 RC1 alone | LAMA0625 | builds | +| SDK 11 RC3 with SDK 10.0.403 beside it | builds, LAMA0617 twice | builds | +| SDK 10.0.403, `net10.0` | builds | builds | + +A console project builds on 2026.1 in every case, so the failure is the web SDK's Razor compiler, which needs Roslyn +5.11 (RC1) or 5.12 (RC3) where Metalama 2026.1 bundles 5.9. With 2027, one project on `net10.0;net11.0` and no +`LangVersion` compiles `net10.0` at C# 14.0 and `net11.0` at 15.0, the value object is generated on both, and a union +under `#if NET11_0_OR_GREATER` or in a file removed from `net10.0` builds on both targets. This machine has a Metalama +license entry for 2027.0, so these runs say nothing about a build without one; decision 120's clean-container run of +2027.0.4-preview did, and the CI condition stays. + +## Consequences + +- The roadmap's Metalama item moves to 2.4.0. #173 (the move), #272 (a union over value objects in a woven project) + and #223 (what the generators do with a union or a `closed` class) move from the 2.5.0 epic to the 2.4.0 epic: + the release that makes a woven project compile those shapes defines what they do, since a value object over a union + that compiles with no defined answer is the silent failure this repository refuses. 2.5.0 keeps what 2027.0 offers + beyond that: AspectTesting on xunit.v3 (#220), the aspect-author analyzers (#221), type facets (#222) and the + platform requirement (#224). +- Decision 120's rule 2 sentence "until 2.5.0 a union member reaches the consumers without the Generators package" + ends at 2.4.0: from 2.4.0 a woven `net11.0` project compiles at C# 15, so #209 and #210 reach every consumer. +- #275 closes when 2.4.0 ships on 2027.0; #281 is the lane. +- Decision 120's status and index row name this record. diff --git a/design/adr/README.md b/design/adr/README.md index 713fed2..9372c43 100644 --- a/design/adr/README.md +++ b/design/adr/README.md @@ -126,7 +126,7 @@ per area ([design](../plan.md)) link to the records they rest on. | [0117](0117-a-seed-is-caught-against-a-passing-baseline.md) | `oracles seeds` credits a seed only when its oracle passes without it, in a baseline run with the same build and filter, and fails with it in a test of its own; a run that never reached the tests (a fixture xunit could not set up, an error counted outside any test, a crashed host, no TRX, every test skipped) or a failing baseline is `ERROR`, exit 4, never `CAUGHT` | 2026-10-29 | accepted | | [0118](0118-an-error-may-learn-a-form-only-new-api-can-write.md) | An Error may report, in a minor version, a form that only an API new in that version can write, since no build that worked before contains it: CMTK0003's dropped assertion of `CodoMetis.TypeKit.Testing` on a `Task` or `ValueTask` in 2.3.0, its `ConfigureAwait`, `WaitAsync` and branch forms (#152) included, known by the package's assembly; the forms freeze at the tag; refines decision 34; one exception the maintainer took into 2.3.0, a dropped `Task.WhenAny` of tasks of results (#159) | 2026-10-29 | accepted; widened by [0119](0119-a-gap-found-before-the-tag-ships-in-that-release.md) | | [0119](0119-a-gap-found-before-the-tag-ships-in-that-release.md) | A form an Error misses, found before its version is tagged, is reported in that version when it loses what the rule protects in every build, though code built on the previous minor can contain it: 2.3.0's CMTK0003 on a `Task.WhenAny` of results (#159), `Wait()` on a branch (#160), an array in `Task.WaitAll`/`WaitAny` (#161), a dropped `Task.WhenEach` (#162), and a `WhenAny` of held tasks silent; the rule stops at the tag, after which decision 34 holds; refines 34 and 118 | 2026-10-29 | accepted | -| [0120](0120-a-net11-0-target-and-documented-floor-raises-join-a-minor.md) | A `net11.0` target joins a 2.x minor when a feature needs it, and a dependency floor may rise in a minor, on every target or on `net11.0` alone, if it is documented (the Semantic Versioning FAQ calls a dependency update with an unchanged public API compatible; a project that references the dependency lower gets NU1605, measured on SDK 11 RC1, so the changelog names the floor, who it reaches and both ways out, and the smoke test shows it); a union new on `net11.0` is an addition and may join a 2.x minor (a `LangVersion` 14 consumer who matches on it gets CS9327, and on Metalama 2026.1 CS8652, measured); Metalama is one version for every target and TypeKit follows the maintained Metalama year in a minor: 2.3 and 2.4 stay on 2026.1 and 2.5.0 moves both targets to 2027.0 once stable (a direct 2026.1 reference gets NU1605 and stays on 2.4.x; a woven `net11.0` project goes from C# 14 to 15; conditions: a license-free CI and clean-container build, the ceiling and the 2.4.x line documented); the SDK 11 spike comes first (#170); 3.0.0 stays the `net10.0` drop and a change of an existing contract, timed to .NET 12 LTS, and .NET 11 is no reason for a major; refines decision 44 | 2026-10-29 | accepted | +| [0120](0120-a-net11-0-target-and-documented-floor-raises-join-a-minor.md) | A `net11.0` target joins a 2.x minor when a feature needs it, and a dependency floor may rise in a minor, on every target or on `net11.0` alone, if it is documented (the Semantic Versioning FAQ calls a dependency update with an unchanged public API compatible; a project that references the dependency lower gets NU1605, measured on SDK 11 RC1, so the changelog names the floor, who it reaches and both ways out, and the smoke test shows it); a union new on `net11.0` is an addition and may join a 2.x minor (a `LangVersion` 14 consumer who matches on it gets CS9327, and on Metalama 2026.1 CS8652, measured); Metalama is one version for every target and TypeKit follows the maintained Metalama year in a minor: 2.3 and 2.4 stay on 2026.1 and 2.5.0 moves both targets to 2027.0 once stable (a direct 2026.1 reference gets NU1605 and stays on 2.4.x; a woven `net11.0` project goes from C# 14 to 15; conditions: a license-free CI and clean-container build, the ceiling and the 2.4.x line documented); the SDK 11 spike comes first (#170); 3.0.0 stays the `net10.0` drop and a change of an existing contract, timed to .NET 12 LTS, and .NET 11 is no reason for a major; refines decision 44 | 2026-10-29 | accepted; its Metalama timing superseded by [0129](0129-metalama-2027-0-moves-into-2-4-0.md) | | [0121](0121-a-generated-member-is-refused-wherever-the-value-object-reaches-it.md) | CMTK1011, and CMTK1008 for comparison, refuse a generated member written by hand wherever a value object or closed set reaches it: on it, in a base record, public or explicit, or as an interface's explicit implementation, in any assembly, found by the interface mapping since Metalama lists no private member of another assembly's type; a base record's `Create` beside the value object's own (#195) and a seam a base record declares (#194) too; `IConvertible`, `IValueObject<,>`, `IValueObjectMaterializer<,>`, `IPlainValueObject<,>` and a set's `IParsable` declared through an interface or by a base record are CMTK1011 where the aspect crashed (#192); a closed set's base class counts as a base record does, its `sealed` `ToString()` the seam and one not sealed refused (#205); an interface's `==` and .NET's own `INumberBase` bridges are not refused; an exception to 34 taken in the patch 2.3.1 (#191, #192, #194, #195, #197, #205) | 2026-10-30 | accepted; refined by [0128](0128-one-signature-identity-and-a-mark-on-every-generated-member.md) | | [0122](0122-arithmetic-operators-are-opt-in-and-a-hand-written-one-is-a-seam.md) | A plain value object gets the arithmetic operators (`+`, `-`, `*`, `/`, `%`, unary `-` and `+`, and their `checked` forms) of the operator interfaces it declares, where the wrapped type implements the same interface with the value object replaced by itself; each calls the wrapped type's through `GeneratedArithmetic`, a constrained generic call with its context stated; never by default and never on a validated value object, which keeps CS0535; a hand-written operator for the same operands, or an explicit implementation of the interface, its own or a base record's, is a seam, kept with its `checked` form, so 2.3 code builds unchanged; refines decision 28 | 2026-10-30 | accepted; refined by [0123](0123-a-hand-written-operator-is-refused-in-a-query.md) and [0124](0124-an-operator-in-a-query-is-the-wrapped-type-s-arithmetic.md) | | [0123](0123-a-hand-written-operator-is-refused-in-a-query.md) | An arithmetic, bitwise or shift operator a value object declares by hand is refused in an EF Core query, naming the value object and `.Value`, by an interceptor and, for query filters, when the model is built; the generated ones carry `[TranslatedAsWrappedArithmetic]`, which is what tells them apart; a conversion operator is left to EF; refines decision 122 | 2026-10-30 | accepted | @@ -135,3 +135,4 @@ per area ([design](../plan.md)) link to the records they rest on. | [0126](0126-parallel-work-runs-in-worktrunk-worktrees-beside-the-repository.md) | Parallel work runs in worktrunk worktrees at `../CodoMetis.TypeKit-worktrees/`, set per machine in worktrunk's user config; worktrunk's default branch is the open `release/`, set per clone, so `wt switch -c`, the plugin's agent worktrees, `wt remove` and `wt step prune` base on it; the Bash guard refuses `wt merge` and `wt step squash`, `rebase` and `push`, since work lands by a PR and a merge commit (decision 94); nothing is copied into a new worktree, which builds the solution cold in 27 s; `.claude/worktrees/` joins `.gitignore`; [design/worktrees.md](../worktrees.md) is the runbook | 2026-10-31 | accepted | | [0127](0127-a-change-to-tools-or-tests-runs-the-test-projects-it-reaches.md) | A change whose paths are prose, the ignore list or inside solution projects under `tools/` and `test/` runs the projects it reaches (`suite=reach`, written as `test/Reach.slnf`): a project reaches its directory, what its items and imports name and what its references reach, and a run-time read by path is declared with `` (the conventions the root, the oracle tests `test/`), which `TestReachTests` holds against MSBuild's evaluation and the sources' literals; anything else, or anything unreadable, runs the whole solution; `.gitignore` is Linux alone; the gate refuses a reached suite with no projects, the pack or macOS; amends decision 113 | 2026-10-31 | accepted | | [0128](0128-one-signature-identity-and-a-mark-on-every-generated-member.md) | Every check of a hand-written member asks one identity, C#'s: a method of the generated one's name, arity, parameter types without nullable annotations (`Nullable` its own type) and by-reference-ness, or another kind of member of its name (in a base too, but a base's method beside a generated property), visible from the value object; the named generated members are entries the aspects introduce through, which name, check and mark them, and the check, the CMTK1005/CMTK1021 names and the refused interfaces read the same entries; every generated member carries `[GeneratedMember(typeof(Contract), "Member")]` from the base package, but the overrides Metalama writes over a record's implicit members, which take no attribute; refines decisions 28 and 121 | 2026-10-31 | accepted | +| [0129](0129-metalama-2027-0-moves-into-2-4-0.md) | The Generators package moves to Metalama 2027.0 in 2.4.0, for both targets, so a consumer with only the .NET 11 SDK builds (on 2026.1 a web project fails there with LAMA0625, on `net10.0` as on `net11.0`, KB-060); 2.4.0 is tagged only on a stable 2027.0; a CI and smoke-test lane with only SDK 11 installed and a web consumer joins decision 120's conditions (#281); 2.3.x is the line below the ceiling; #173, #272 and #223 move to 2.4.0; staying on 2026.1, a 2.4.0 without `net11.0` and a 2.4.0 on the preview were refused; replaces decision 120's Metalama timing | 2026-10-31 | accepted | diff --git a/design/roadmap.md b/design/roadmap.md index 11d478e..b775498 100644 --- a/design/roadmap.md +++ b/design/roadmap.md @@ -58,15 +58,17 @@ Small, each closable in a minor version. Found by the reviews named. converters' trimming warnings decide whether it is a package ([decision 71](adr/0071-converters-say-what-they-write.md)). - A stable external name for a closed-set member, apart from its C# identifier: parsing, JSON, EF, OpenAPI and the fault identifiers at once (proposed in the review of 2026-10-13). -- The Metalama 2027.0 upgrade, in 2.5.0 (#173), once 2027.0 is stable (`2027.0.4-preview` on 2026-10-14; - [decision 4](adr/0004-metalama-2026-1-x-latest-stable.md)), for both targets at once and with 2.3 and 2.4 on - 2026.1 ([decision 120](adr/0120-a-net11-0-target-and-documented-floor-raises-join-a-minor.md)). It raises a floor in - a minor, which decision 120 allows when documented: a project that references `Metalama.Framework` 2026.1 - directly gets NU1605 and stays on TypeKit 2.4.x or raises its reference, and a woven `net11.0` project moves - from C# 14 to 15. Its conditions: a build with no Metalama license passes in CI and a clean container on 2027 - (#170), the weaving review and the smoke test run on it, the changelog and the Generators README name the - ceiling, the language-version change, the supported IDEs and what Metalama 2027 drops, and the release notes - say whether 2.4.x is patched. `[Durable]` returns to the `_value` placeholder with it. +- The Metalama 2027.0 upgrade, in 2.4.0 (#173), which is tagged only once 2027.0 is stable (`2027.0.5-preview` on + 2026-10-31; [decision 4](adr/0004-metalama-2026-1-x-latest-stable.md)), for both targets at once and with 2.3 on + 2026.1 ([decision 129](adr/0129-metalama-2027-0-moves-into-2-4-0.md), which moved it from 2.5.0 because on 2026.1 a + web project fails with LAMA0625 where SDK 11 is the only SDK). It raises a floor in a minor, which + [decision 120](adr/0120-a-net11-0-target-and-documented-floor-raises-join-a-minor.md) allows when documented: a + project that references `Metalama.Framework` 2026.1 directly gets NU1605 and stays on TypeKit 2.3.x or raises its + reference, and a woven `net11.0` project moves from C# 14 to 15. Its conditions: a build with no Metalama license + passes in CI and a clean container on 2027 (#170), a CI and smoke-test lane with only SDK 11 installed builds a web + consumer (#281), the weaving review and the smoke test run on it, the changelog and the Generators README name the + ceiling, the language-version change, the supported IDEs and what Metalama 2027 drops, and the release notes say + whether 2.3.x is patched. `[Durable]` returns to the `_value` placeholder with it. - A `net11.0` target beside `net10.0`, in a 2.x minor when a feature needs it ([decision 44](adr/0044-2-0-0-net10-0-metalama.md)), on the terms of [decision 120](adr/0120-a-net11-0-target-and-documented-floor-raises-join-a-minor.md): a higher floor in the `net11.0` group (EF Core 11 and Microsoft.AspNetCore.OpenApi 11 in the satellites) allowed when the From 0f89b272da7ae65231dca446c8ee88225e39645c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gro=C3=9F?= Date: Sat, 28 Nov 2026 13:20:31 +0100 Subject: [PATCH 02/13] build: the Generators package on Metalama 2027.0.9-preview, as 2.4.0-preview.1 Metalama.Framework moves from 2026.1.30 to 2027.0.9-preview, and the version to 2.4.0-preview.1, since a stable package cannot depend on a prerelease (NU5104). 2.4.0 stays a preview until Metalama 2027.0 is stable (#173, #284). What the 2027 compiler asked for: - LAMA0891: two static tables of the aspects were arrays, which are mutable. They are ImmutableArray now. - The value placeholder does not need [Durable] on this preview: the build passes under warnings as errors without it, so the note that expected it goes. Measured on SDK 10.0.404, macOS arm64: the solution builds, and the suite is 36119 passed of 37480 with 1252 skipped; its 109 failures were all the pack of the Generators package under version 2.4.0 (NU5104), which the version fixes (Conventions: 2089 passed). Refs #173 Co-Authored-By: Claude Fable 5.2 --- CHANGELOG.md | 2 +- Directory.Build.props | 2 +- Directory.Packages.props | 4 ++-- .../ValueObjectAspect.Templates.cs | 3 --- .../ValueObjectConvertibleAspect.cs | 3 ++- src/CodoMetis.TypeKit.Generators/ValueObjectJsonAspect.cs | 3 ++- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 583c1e8..6e8ad17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ A version's heading reads `## — Unreleased` until the release is pre the release date. The release workflow refuses a tag whose section still says `Unreleased`, and the section is the GitHub release's notes. -## 2.4.0 — Unreleased +## 2.4.0-preview.1 — Unreleased ### Added diff --git a/Directory.Build.props b/Directory.Build.props index 69c73cc..6c39a48 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 2.4.0 + 2.4.0-preview.1 CaffeinatedCoder Copyright (c) 2026 CaffeinatedCoder MIT diff --git a/Directory.Packages.props b/Directory.Packages.props index 699da86..46cd85f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -7,8 +7,8 @@ one is a release decision, not a dependency update. --> - - + + + + + + + + + + + + + + + diff --git a/design/adr/0132-on-ef-core-11-a-ulong-or-char-key-s-temporary-value-is-a-factory-on-the-property.md b/design/adr/0132-on-ef-core-11-a-ulong-or-char-key-s-temporary-value-is-a-factory-on-the-property.md new file mode 100644 index 0000000..8843034 --- /dev/null +++ b/design/adr/0132-on-ef-core-11-a-ulong-or-char-key-s-temporary-value-is-a-factory-on-the-property.md @@ -0,0 +1,83 @@ +# 0132. On EF Core 11, the temporary value of a key over `ulong` or `char` is a generator factory on the property + +Date: 2026-11-28 +Status: accepted + +Context: 2026-11-28, issue #285; [EF Core](../ef-core.md). On EF Core 11, +[decision 114](0114-a-value-object-s-temporary-number-is-its-wrapped-type-s.md)'s route is gone. Decision 114 carried a value +generator factory in the `ConverterMappingHints` of the converter `UseTypeKit()` composes, which `CoreTypeMapping` +took into the value object's mapping, and noted that the property was `[Obsolete]` in EF Core 10: "A later EF that +removes it fails the tests that hold this, not silently." EF Core 11.0.0 removed the constructor parameter, the +`ValueGeneratorFactory` of the hints and of `CoreTypeMapping`, and the selector's read of it +(`ValueGeneratorSelector.Find`, compared at `v10.0.12` and `v11.0.0`). The published 2.3.1 package, compiled +against EF Core 10, throws `MissingMethodException` on EF Core 11 for the first value object mapped (#285). + +Without a replacement, EF Core 11 chooses a generated value object's temporary number by the converter's provider +type (`ValueGeneratorSelector.TryCreate`, then `TemporaryNumberValueGeneratorFactory.Create`). That is right +wherever the column is of the wrapped type, and wrong in the two cases decision 114 names: a key over `ulong` +where the column is a `decimal` gets a negative temporary `decimal`, which throws `OverflowException` converted +back, and a key over `char` configured on add gets a character of a GUID string on SQL Server. + +## Decision + +**On the `net11.0` asset, a value object over `ulong` or `char` that EF generates on add gets +`WrappedTypeValueGeneratorFactory` on the property**, set by `ValueObjectValueGeneratorConvention` at the +convention's level, as a value object over a `Guid` or a `string` already does. The generator +asks the provider, at the first value, for the generator of a key of the wrapped type in a model of its own, and +converts its values. So the temporary values are the plain key's, by construction. + +- A number keeps the factory beside a default or computed SQL value, where a `Guid` or a `string` is left to EF: + a plain `ulong` key gets a temporary number there too, and a TPC key's sequence is such a default. +- The other numbers get no factory. EF's choice by the provider type is the plain key's wherever the column is + of the wrapped type, and a factory on the property would come before HiLo for every one of them. +- **The `net10.0` asset is unchanged**: the hints, as decision 114 has them. The two assets differ in the three + ways below, because EF differs, which decision 120's second rule ("a shared member behaves the same on both") + does not reach: no member of this package changes. + +**What differs on EF Core 11, measured:** + +1. **SQL Server's HiLo is not chosen for a key over `ulong`**, where EF Core 10 chooses it. SQL Server's selector + takes a factory on the property before HiLo (`SqlServerValueGeneratorSelector.TrySelect`), and EF Core 11 + leaves no place after it. The key gets a temporary value, and `SaveChanges` then fails on the column, which + has no identity: loud, at the first insert. The way out is one line, which a test holds: + `Property(e => e.Id).Metadata.SetValueGeneratorFactory((Type?)null)`, after which HiLo is chosen. A key over + `ulong` with HiLo is refused by PostgreSQL's provider, plain or value object, so SQL Server is the one case. +2. **A `--nativeaot` compiled model gives a default `ulong` key its temporary value**, where it throws + `OverflowException` on EF Core 10: a compiled model names a factory type, and could not write the delegate in + the hints. +3. **So does a key whose converter the application names by hand** + (`HasConversion>()`), for the same reason: the factory is the + property's, whatever converter its mapping is built on. + +Refused: + +- **No replacement, and the `ulong` case documented as throwing.** It is decision 63's state, which decision 114 + left: a default key that throws at `Add` on two providers, against one configuration, HiLo on SQL Server over + `ulong`, that fails at `SaveChanges` and has a one-line way out. +- **Reading the provider's HiLo annotation to leave such a key alone.** It names a provider's annotation, and + discovery here is never by name. +- **Replacing or decorating `IValueGeneratorSelector`.** `UseTypeKit()` replaces nothing, and two packages that + replace one EF service cannot be installed together. +- **Seeding EF's value generator cache.** It would come after HiLo, as the hints did, and rests on the cache's key + and lifetime, which are EF's own. + +## Evidence + +EF Core 11.0.0, Npgsql 11.0.0 and SQL Server's provider 11.0.0, `net11.0`, macOS arm64, 2026-11-28. No database is +opened for the generator tests, as in decision 114. + +- With the hints compiled out and nothing in their place, 18 tests fail on `net11.0`: `KeyGenerationTests` (4, + `OverflowException` at `Add` on SQL Server and PostgreSQL, compiled model included), `KeyGenerationVariantTests` + (3: `ulong` on both providers, `char` on SQL Server), `SqlServerKeyVariantTests` (11 key shapes over `ulong`). +- With the factory, all of them pass, and three tests changed their answer, which are the three differences above. + With the factory withheld beside a default SQL value, the two TPC shapes of `SqlServerKeyVariantTests` still + throw. +- `KeyGenerationTests` holds each difference per target: HiLo pinned as not chosen on `net11.0` and chosen once + the factory is cleared, the Native AOT compiled model and the converter named by hand as temporary values on + `net11.0` and as throwing on `net10.0`. The key-generation classes pass on both targets (1226). + +## Consequences + +- [The EF Core note](../ef-core.md) and the package README say what differs on EF Core 11, and the changelog's + "Changed" names the HiLo case with its way out. +- Decision 114 stands for the `net10.0` asset. When `net10.0` is dropped (3.0.0), this is the only route. diff --git a/design/adr/README.md b/design/adr/README.md index efa6229..ec89654 100644 --- a/design/adr/README.md +++ b/design/adr/README.md @@ -120,7 +120,7 @@ per area ([design](../plan.md)) link to the records they rest on. | [0111](0111-a-mapping-can-withhold-the-fault-name.md) | A mapping withholds a member's name with `FaultResponse.WithoutFaultName()`: its problem has no `fault`, no `rule` and no member description as its detail; `IFaultFeature.NameWithheld` tells the host; a response whose every fault withholds its name is described as naming none; the same-name warning counts only members that write their name | 2026-10-28 | accepted | | [0112](0112-the-prober-gives-way-to-valueranges-oracle-kit.md) | The prober, its corpus, its seeds, the CI replay and the release gate are retired for CodoMetis.ValueRanges' oracle kit under `test/oracles/`: claims quoted verbatim and held by named tests, every public member claimed or waived, oracles as ordinary test classes each with a seed CI checks applies, candidates, and a hand-written axes file; `tools/Oracles seeds` builds one project and runs one class per seed | 2026-10-28 | accepted | | [0113](0113-ci-runs-the-lanes-a-change-can-affect.md) | CI runs the lanes a change can affect: each changed path selects Linux, Windows and the pack by its class in `tools/CiLanes` (Windows for the analyzers, the generators, tests and tools; the pack for the packages), a path no class names selects all three, a prose-only change runs only the test projects that read prose (`test/Prose.slnf`), and only a pull request into `main`, a push to `main`, the nightly and the release run macOS; a gate job, `CI`, over every job is the required check; a convention test refuses non-portable file names; `release.yml` calls the build workflow before it verifies | 2026-10-29 | accepted; amended by [0127](0127-a-change-to-tools-or-tests-runs-the-test-projects-it-reaches.md) | -| [0114](0114-a-value-object-s-temporary-number-is-its-wrapped-type-s.md) | A value object over a number gets the temporary values a property of its wrapped type gets, from a factory in its converter's mapping hints, which EF consults after a generator on the property and after HiLo: a default `ulong` key no longer throws at `Add`, and a `char` key configured on add gets a temporary `char` on SQL Server; under `--nativeaot` the factory is lost and a default `ulong` key still throws | 2026-10-29 | accepted | +| [0114](0114-a-value-object-s-temporary-number-is-its-wrapped-type-s.md) | A value object over a number gets the temporary values a property of its wrapped type gets, from a factory in its converter's mapping hints, which EF consults after a generator on the property and after HiLo: a default `ulong` key no longer throws at `Add`, and a `char` key configured on add gets a temporary `char` on SQL Server; under `--nativeaot` the factory is lost and a default `ulong` key still throws | 2026-10-29 | accepted; refined by [0132](0132-on-ef-core-11-a-ulong-or-char-key-s-temporary-value-is-a-factory-on-the-property.md) | | [0115](0115-value-objects-can-be-inlined-everywhere.md) | `AddTypeKit(typeKit => typeKit.InlineValueObjects = true)` writes every value object in place, by its wrapped type's schema, in every position and version, with no component of its own; off by default, the document unchanged; closed sets and wrapped enums keep their components; an inlined value object claims no name (decision 55) and shares no schema between its JSON positions and its parameters (decision 106) | 2026-10-29 | accepted | | [0116](0116-the-docs-site-is-docfx-built-from-main.md) | The docs site is DocFX, published to GitHub Pages from `main` alone: the guides, the READMEs, the changelog and the API pages of the run-time packages, from the files as they are; a link to a file that is not a page becomes a GitHub address at the built commit; a pull request touching a page builds it with warnings as errors; `site/**` is prose; DocFX 2.81.0 lists the members of C# 14 extension blocks as extension methods | 2026-10-29 | accepted | | [0117](0117-a-seed-is-caught-against-a-passing-baseline.md) | `oracles seeds` credits a seed only when its oracle passes without it, in a baseline run with the same build and filter, and fails with it in a test of its own; a run that never reached the tests (a fixture xunit could not set up, an error counted outside any test, a crashed host, no TRX, every test skipped) or a failing baseline is `ERROR`, exit 4, never `CAUGHT` | 2026-10-29 | accepted | @@ -138,3 +138,4 @@ per area ([design](../plan.md)) link to the records they rest on. | [0129](0129-metalama-2027-0-moves-into-2-4-0.md) | The Generators package moves to Metalama 2027.0 in 2.4.0, for both targets, so a consumer with only the .NET 11 SDK builds (on 2026.1 a web project fails there with LAMA0625, on `net10.0` as on `net11.0`, KB-060); 2.4.0 is tagged only on a stable 2027.0; a CI and smoke-test lane with only SDK 11 installed and a web consumer joins decision 120's conditions (#281); 2.3.x is the line below the ceiling; #173, #272 and #223 move to 2.4.0; staying on 2026.1, a 2.4.0 without `net11.0` and a 2.4.0 on the preview were refused; replaces decision 120's Metalama timing | 2026-10-31 | accepted; amended by [0130](0130-2-4-0-is-published-as-previews-on-the-current-metalama-2027-preview.md) | | [0130](0130-2-4-0-is-published-as-previews-on-the-current-metalama-2027-preview.md) | Every 2.4.0 version is built on the current Metalama 2027 preview and is published as `2.4.0-preview.N` until Metalama 2027.0 is stable; `v2.4.0` is still tagged only on a stable 2027.0, a new Metalama preview is taken by a change of its own, and each preview has its changelog section. Amends decision 129 | 2026-11-28 | accepted | | [0131](0131-the-sdk-pin-moves-to-11-0-1xx.md) | `global.json` pins SDK 11.0.100 with `latestPatch`, after the Generators package is on Metalama 2027 (on 2026.1.30 the repository fails there with CS8034), and every fact pinned to the SDK band is run again on the new one | 2026-11-28 | accepted | +| [0132](0132-on-ef-core-11-a-ulong-or-char-key-s-temporary-value-is-a-factory-on-the-property.md) | On EF Core 11, which removed the factory a type mapping took from its converter's hints (decision 114), a value object over `ulong` or `char` generated on add gets `WrappedTypeValueGeneratorFactory` on the property; SQL Server's HiLo then is not chosen for a `ulong` key unless the application clears the factory, and a Native AOT compiled model and a converter named by hand get the temporary value they lacked | 2026-11-28 | accepted | diff --git a/docs/ef-core.md b/docs/ef-core.md index 9e31d8e..241d000 100644 --- a/docs/ef-core.md +++ b/docs/ef-core.md @@ -130,11 +130,15 @@ A composite key of value objects is `HasKey(x => new { x.Order, x.Line })`, as f - **A key over `char` is always yours to assign**, on every provider, since none generates one. A default `'\0'` is stored as it is, so assign a meaningful character. -- **Under Native AOT, a key over `ulong` needs `ValueGeneratedNever()` on SQL Server and PostgreSQL.** +- **On EF Core 10 under Native AOT, a key over `ulong` needs `ValueGeneratedNever()` on SQL Server and PostgreSQL.** Their column is a `decimal`, and in a compiled model made with `--nativeaot`, adding the entity with the key's default value throws `OverflowException` at `Add`. The same goes for a key you configure with `ValueObjectConverter` yourself. Configure `ValueGeneratedNever()` and assign the key. - Otherwise it gets a temporary value, as a plain `ulong` key does. + Otherwise it gets a temporary value, as a plain `ulong` key does. On EF Core 11 it gets one in + those two cases as well. +- **On EF Core 11, a key over `ulong` with SQL Server's HiLo needs one more line.** HiLo isn't chosen + until you clear the generator factory TypeKit sets on the key. The + [package README](../src/CodoMetis.TypeKit.EntityFrameworkCore/README.md#keys) has the line. - **Inheritance hierarchies.** The root of a TPH or TPT hierarchy is generated too. Under TPC, as for an `int` key, it's generated only where the provider has a sequence for the hierarchy (PostgreSQL, SQL Server), not on SQLite. @@ -273,7 +277,8 @@ types makes a round trip through a real PostgreSQL and a real SQL Server. - **A struct value object is stored as it is, or a class one fails the model.** The provider has no relational type mapping. EF's in-memory provider does that, so use SQLite. -- **NU1605 on restore.** You reference an EF Core package below 10.0.12 directly. Raise it. +- **NU1605 on restore.** You reference an EF Core package directly, below 10.0.12 on .NET 10 or below + 11.0.0 on .NET 11. Raise it. - **A convention doesn't reach a value object.** It was configured by the underlying type. Configure it by the value object's type. - **Every migration repeats an `AlterColumn` on SQLite.** An integer key is missing diff --git a/src/CodoMetis.TypeKit.EntityFrameworkCore/CodoMetis.TypeKit.EntityFrameworkCore.csproj b/src/CodoMetis.TypeKit.EntityFrameworkCore/CodoMetis.TypeKit.EntityFrameworkCore.csproj index 73dacbb..d5f6384 100644 --- a/src/CodoMetis.TypeKit.EntityFrameworkCore/CodoMetis.TypeKit.EntityFrameworkCore.csproj +++ b/src/CodoMetis.TypeKit.EntityFrameworkCore/CodoMetis.TypeKit.EntityFrameworkCore.csproj @@ -1,4 +1,9 @@ + + + + net10.0;net11.0 + diff --git a/src/CodoMetis.TypeKit.EntityFrameworkCore/README.md b/src/CodoMetis.TypeKit.EntityFrameworkCore/README.md index 24478f3..ef124a2 100644 --- a/src/CodoMetis.TypeKit.EntityFrameworkCore/README.md +++ b/src/CodoMetis.TypeKit.EntityFrameworkCore/README.md @@ -1,7 +1,7 @@ # CodoMetis.TypeKit.EntityFrameworkCore Use [CodoMetis.TypeKit](https://www.nuget.org/packages/CodoMetis.TypeKit) value objects in EF Core -10 with one line of setup. Every value object is stored in a plain column of its underlying type, +10 or 11 with one line of setup. Every value object is stored in a plain column of its underlying type, with nothing to register per type, and `.Value` works in a LINQ query the way it does in memory. ```bash @@ -13,9 +13,10 @@ This page is the reference for the package. For a walk through a whole model, re **Good to know** -- **It needs EF Core 10.0.12 or later.** A project that references `Microsoft.EntityFrameworkCore` - or `Microsoft.EntityFrameworkCore.Relational` directly at an earlier version fails to restore with - NU1605 (a package downgrade). Keep the EF Core packages at 10.0.12 or later. +- **It needs EF Core 10.0.12 or later on .NET 10, and EF Core 11.0.0 or later on .NET 11.** A project + that references `Microsoft.EntityFrameworkCore` or `Microsoft.EntityFrameworkCore.Relational` + directly at an earlier version fails to restore with NU1605 (a package downgrade). Raise the EF Core + packages to that version or later. - **The generators stay in your domain project.** This package recognises a value object at run time by the attribute the generators put on it. So the project that hosts the `DbContext` needs only this package and the base package. The domain project that declares the value objects references @@ -89,7 +90,7 @@ On PostgreSQL, for example, a `ulong` is a `numeric(20,0)`, which can't be an id At `Add`, a key that is generated gets the same temporary value a plain key of the underlying type gets, also where the column is of another type, such as the `decimal` that holds a `ulong`. HiLo and a -value generator of your own still come first. There are two exceptions: +value generator of your own still come first. There are three exceptions: - **A key over `char` is yours to assign.** It's never generated, on any provider, because none generates a `char` key. PostgreSQL rejects an identity on `character(1)`, SQLite an `AUTOINCREMENT` @@ -98,13 +99,20 @@ value generator of your own still come first. There are two exceptions: value, but it doesn't check that you set a meaningful one. A default key, `'\0'`, is stored as it is, and a second such row fails on the primary key. `ValueGeneratedOnAdd()` or a value generator of your own on the property still applies. -- **A default key over `ulong` can still throw at `Add`** where the column is a `decimal` (SQL +- **On EF Core 10, a default key over `ulong` can still throw at `Add`** where the column is a `decimal` (SQL Server, PostgreSQL), in two cases. One is a compiled model made with `dotnet ef dbcontext optimize --nativeaot`, which writes each column's mapping out as code and loses what gives the key a temporary `ulong`. The other is a key you configure with `ValueObjectConverter` yourself. EF's temporary value for the column is then a negative `decimal`, and converting it back throws `OverflowException`. Otherwise the key gets a temporary `ulong`, as a plain one does. In those two - cases, configure `ValueGeneratedNever()` on the key and assign it. + cases, configure `ValueGeneratedNever()` on the key and assign it. On EF Core 11 neither case + throws: the key gets its temporary `ulong` in both. +- **On EF Core 11, SQL Server's HiLo isn't chosen for a key over `ulong`.** EF Core 11 leaves TypeKit + one place to give that key its temporary `ulong`, a generator factory on the property, and SQL + Server takes such a factory before HiLo. `SaveChanges` then fails, because the column has no + identity. Clear the factory on the key and HiLo is chosen again: + `Property(o => o.Id).Metadata.SetValueGeneratorFactory((Type?)null)`. On EF Core 10 you need + nothing: HiLo comes first there. A key over a `Guid` is yours to assign, `Id = OrderId.New()` (a version 7 Guid, which sorts by creation time), and EF inserts it as given. To have EF generate it instead, configure diff --git a/src/CodoMetis.TypeKit.EntityFrameworkCore/ValueObjectKeyValueGenerationConvention.cs b/src/CodoMetis.TypeKit.EntityFrameworkCore/ValueObjectKeyValueGenerationConvention.cs index 68def30..ec432fb 100644 --- a/src/CodoMetis.TypeKit.EntityFrameworkCore/ValueObjectKeyValueGenerationConvention.cs +++ b/src/CodoMetis.TypeKit.EntityFrameworkCore/ValueObjectKeyValueGenerationConvention.cs @@ -144,11 +144,18 @@ public void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConven foreach (var property in entityType.GetDeclaredProperties()) { if (property.ValueGenerated == ValueGenerated.Never || property.GetValueGeneratorFactory() is not null) continue; - if (property.GetDefaultValueSql() is not null || property.GetComputedColumnSql() is not null) continue; - if (ValueObjectTypes.Describe(Nullable.GetUnderlyingType(property.ClrType) ?? property.ClrType) is { WrappedType: var wrapped } - && WrappedTypeValueGenerator.Generates(wrapped)) - property.Builder.HasValueGeneratorFactory(typeof(WrappedTypeValueGeneratorFactory)); + if (ValueObjectTypes.Describe(Nullable.GetUnderlyingType(property.ClrType) ?? property.ClrType) is not { WrappedType: var wrapped } + || !WrappedTypeValueGenerator.Generates(wrapped)) + continue; + + // A number gets its temporary value with a default or computed SQL value too, as the plain key does + // (a TPC key's sequence is one); a Guid or a string then gets EF's temporary value, not the provider's. + if (!WrappedTypeValueGenerator.IsTemporaryNumber(wrapped) + && (property.GetDefaultValueSql() is not null || property.GetComputedColumnSql() is not null)) + continue; + + property.Builder.HasValueGeneratorFactory(typeof(WrappedTypeValueGeneratorFactory)); } } } diff --git a/src/CodoMetis.TypeKit.EntityFrameworkCore/ValueObjectMapping.cs b/src/CodoMetis.TypeKit.EntityFrameworkCore/ValueObjectMapping.cs index 01950dd..cd8c547 100644 --- a/src/CodoMetis.TypeKit.EntityFrameworkCore/ValueObjectMapping.cs +++ b/src/CodoMetis.TypeKit.EntityFrameworkCore/ValueObjectMapping.cs @@ -3,6 +3,7 @@ using System.Reflection; using CodoMetis.TypeKit.CompilerServices; using CodoMetis.TypeKit.ValueObjects; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.ValueGeneration; @@ -63,6 +64,9 @@ public static ValueObjectMapping For(GeneratedValueObjectAttribute valueObject) /// public abstract bool StoresTheWrappedValue(ValueConverter converter, ValueConverter? wrappedConverter); + /// The generator the provider gives a key of the wrapped type generated on add (). + public abstract ValueGenerator WrappedTypeGenerator(DbContext context); + public RelationalTypeMapping ComposeOnto(RelationalTypeMapping wrapped) => (RelationalTypeMapping)wrapped.WithComposedConverter(Converter, jsonValueReaderWriter: ReaderWriterOver(wrapped.JsonValueReaderWriter)); @@ -70,14 +74,25 @@ private sealed class Of : ValueObjectMapping where TValueObject : IValueObject, IValueObjectMaterializer where T : notnull { +#if NET11_0_OR_GREATER + public Of() => + Converter = new ValueConverter( + ValueObjectConverter.ToProvider, + ValueObjectConverter.FromProvider); +#else public Of() => Converter = new ValueConverter( ValueObjectConverter.ToProvider, ValueObjectConverter.FromProvider, IsTemporaryNumber ? new ConverterMappingHints(valueGeneratorFactory: TemporaryNumber) : null); +#endif public override ValueConverter Converter { get; } + public override ValueGenerator WrappedTypeGenerator(DbContext context) => WrappedTypeValueGenerator.ProviderGenerator(context); + +#if !NET11_0_OR_GREATER + /// /// The types EF gives a generated property a temporary number of (RelationalValueGeneratorSelector.FindForType /// in EF Core 10), chosen by the property's type mapping: for a value object that is its own, so EF fell back to @@ -99,6 +114,7 @@ private ValueGenerator TemporaryNumber(IProperty property, IEntityType entityTyp property.GetTypeMapping().Converter?.ProviderClrType == typeof(T) ? new WrappedTypeValueGenerator(Converter, new TemporaryNumberValueGeneratorFactory().Create(property, entityType)) : new WrappedTypeValueGenerator(Converter, WrappedTypeValueGenerator.ProviderGenerator); +#endif private static readonly MethodInfo ProviderValue = ((MethodCallExpression)ValueObjectConverter.ToProvider.Body).Method; diff --git a/src/CodoMetis.TypeKit.EntityFrameworkCore/WrappedTypeValueGeneratorFactory.cs b/src/CodoMetis.TypeKit.EntityFrameworkCore/WrappedTypeValueGeneratorFactory.cs index c6e564d..61d30f4 100644 --- a/src/CodoMetis.TypeKit.EntityFrameworkCore/WrappedTypeValueGeneratorFactory.cs +++ b/src/CodoMetis.TypeKit.EntityFrameworkCore/WrappedTypeValueGeneratorFactory.cs @@ -39,13 +39,14 @@ public override ValueGenerator Create(IProperty property, ITypeBase typeBase) { ArgumentNullException.ThrowIfNull(property); - return ValueObjectTypes.Describe(Nullable.GetUnderlyingType(property.ClrType) ?? property.ClrType) is { } valueObject - && WrappedTypeValueGenerator.Generates(valueObject.WrappedType) - ? new WrappedTypeValueGenerator( - ValueObjectMapping.For(valueObject).Converter, - valueObject.WrappedType == typeof(Guid) ? WrappedTypeValueGenerator.ProviderGenerator : WrappedTypeValueGenerator.ProviderGenerator) - : throw new InvalidOperationException( - $"{property.DeclaringType.DisplayName()}.{property.Name} is no value object over a Guid or a string, so it has no generator of its wrapped type's."); + if (ValueObjectTypes.Describe(Nullable.GetUnderlyingType(property.ClrType) ?? property.ClrType) is not { } valueObject + || !WrappedTypeValueGenerator.Generates(valueObject.WrappedType)) + throw new InvalidOperationException( + $"{property.DeclaringType.DisplayName()}.{property.Name} is no value object over {WrappedTypeValueGenerator.GeneratedTypes}, so it has no generator of its wrapped type's."); + + var mapping = ValueObjectMapping.For(valueObject); + + return new WrappedTypeValueGenerator(mapping.Converter, mapping.WrappedTypeGenerator); } } @@ -63,9 +64,33 @@ public WrappedTypeValueGenerator(ValueConverter converter, ValueGenerator provid : this(converter, _ => provider) => _provider = provider; +#if NET11_0_OR_GREATER + /// + /// The wrapped types whose generator is the provider's for a key of that type: a and a + /// , whose generator the providers choose by the property's CLR type, and on EF Core 11 a + /// and a , whose temporary value EF chooses by the column's type where the + /// provider stores them as another (a decimal, a string). EF Core 11 has no factory on a type mapping, where + /// EF Core 10 took it from the converter's hints (). + /// + public static bool Generates(Type wrapped) => + wrapped == typeof(Guid) || wrapped == typeof(string) || wrapped == typeof(ulong) || wrapped == typeof(char); + + /// The types of , for a message. + public const string GeneratedTypes = "a Guid, a string, a ulong or a char"; + + /// The types of whose generated value is a temporary number, which the database replaces. + public static bool IsTemporaryNumber(Type wrapped) => wrapped == typeof(ulong) || wrapped == typeof(char); +#else /// The wrapped types whose generator the providers choose by the property's CLR type. public static bool Generates(Type wrapped) => wrapped == typeof(Guid) || wrapped == typeof(string); + /// The types of , for a message. + public const string GeneratedTypes = "a Guid or a string"; + + /// None on EF Core 10, where a number's temporary value is its type mapping's (). + public static bool IsTemporaryNumber(Type wrapped) => false; +#endif + /// EF reads it after a value is generated (ValueGenerationManager in EF Core 10). public override bool GeneratesTemporaryValues => _provider?.GeneratesTemporaryValues diff --git a/test/CodoMetis.TypeKit.Conventions.Tests/PackageDependencyTests.cs b/test/CodoMetis.TypeKit.Conventions.Tests/PackageDependencyTests.cs index 02534da..976810d 100644 --- a/test/CodoMetis.TypeKit.Conventions.Tests/PackageDependencyTests.cs +++ b/test/CodoMetis.TypeKit.Conventions.Tests/PackageDependencyTests.cs @@ -43,11 +43,19 @@ public void The_package_depends_on_the_base_package_of_its_own_version(string pa { var nuspec = packs.Nuspec(package); - var dependency = Dependencies(nuspec).SingleOrDefault(element => (string?)element.Attribute("id") == BasePackage); - - dependency.ShouldNotBeNull($"{package} does not depend on {BasePackage}, so a consumer that installs only {package} gets no contracts."); - ((string?)dependency.Attribute("version")).ShouldBe(Version(packs.Nuspec(BasePackage)), - $"{package} depends on another version of {BasePackage} than the one released with it."); + // One group per target framework: a package with a net11.0 asset beside net10.0 has two (decision 120). + var groups = nuspec.Descendants().Where(element => element.Name.LocalName == "group" && element.Parent?.Name.LocalName == "dependencies").ToList(); + groups.ShouldNotBeEmpty($"{package} declares no dependency group, so a consumer that installs only {package} gets no contracts."); + + foreach (var group in groups) + { + var target = (string?)group.Attribute("targetFramework"); + var dependency = group.Elements().SingleOrDefault(element => (string?)element.Attribute("id") == BasePackage); + + dependency.ShouldNotBeNull($"{package} does not depend on {BasePackage} for {target}, so a consumer that installs only {package} gets no contracts."); + ((string?)dependency.Attribute("version")).ShouldBe(Version(packs.Nuspec(BasePackage)), + $"{package} depends, for {target}, on another version of {BasePackage} than the one released with it."); + } } [Theory] diff --git a/test/CodoMetis.TypeKit.EntityFrameworkCore.Tests/CodoMetis.TypeKit.EntityFrameworkCore.Tests.csproj b/test/CodoMetis.TypeKit.EntityFrameworkCore.Tests/CodoMetis.TypeKit.EntityFrameworkCore.Tests.csproj index ce8a11d..e0f56ed 100644 --- a/test/CodoMetis.TypeKit.EntityFrameworkCore.Tests/CodoMetis.TypeKit.EntityFrameworkCore.Tests.csproj +++ b/test/CodoMetis.TypeKit.EntityFrameworkCore.Tests/CodoMetis.TypeKit.EntityFrameworkCore.Tests.csproj @@ -1,4 +1,9 @@ + + + + net10.0;net11.0 + + + diff --git a/docs/aspnet-core.md b/docs/aspnet-core.md index f2c6af0..37f89ad 100644 --- a/docs/aspnet-core.md +++ b/docs/aspnet-core.md @@ -61,7 +61,7 @@ reference the generators. **Good to know** -- **Reference `Microsoft.AspNetCore.OpenApi` directly, at 10.0.12 or later.** The package README +- **Reference `Microsoft.AspNetCore.OpenApi` directly, at 10.0.12 or later on .NET 10 and at 11.0.0 or later on .NET 11.** The package README explains why ([Setup](../src/CodoMetis.TypeKit.AspNetCore/README.md#setup)). ## Bind value objects in a minimal API diff --git a/src/CodoMetis.TypeKit.AspNetCore/CodoMetis.TypeKit.AspNetCore.csproj b/src/CodoMetis.TypeKit.AspNetCore/CodoMetis.TypeKit.AspNetCore.csproj index e8fecc1..38b93c3 100644 --- a/src/CodoMetis.TypeKit.AspNetCore/CodoMetis.TypeKit.AspNetCore.csproj +++ b/src/CodoMetis.TypeKit.AspNetCore/CodoMetis.TypeKit.AspNetCore.csproj @@ -1,4 +1,9 @@ + + + + net10.0;net11.0 + diff --git a/src/CodoMetis.TypeKit.AspNetCore/FaultResponsesOperationTransformer.cs b/src/CodoMetis.TypeKit.AspNetCore/FaultResponsesOperationTransformer.cs index 50f033f..bda33d3 100644 --- a/src/CodoMetis.TypeKit.AspNetCore/FaultResponsesOperationTransformer.cs +++ b/src/CodoMetis.TypeKit.AspNetCore/FaultResponsesOperationTransformer.cs @@ -9,6 +9,12 @@ using Microsoft.Extensions.Options; using Microsoft.OpenApi; using HttpJsonOptions = Microsoft.AspNetCore.Http.Json.JsonOptions; +#if NET11_0_OR_GREATER +// Microsoft.OpenApi 3, which Microsoft.AspNetCore.OpenApi 11 brings: a response's content is of the interface. +using MediaType = Microsoft.OpenApi.IOpenApiMediaType; +#else +using MediaType = Microsoft.OpenApi.OpenApiMediaType; +#endif namespace CodoMetis.TypeKit.AspNetCore; @@ -134,7 +140,7 @@ public async Task TransformAsync(OpenApiOperation operation, OpenApiOperationTra operation.Responses[key] = new OpenApiResponse { Description = Description(status, types, named.Contains(status)), - Content = new Dictionary { ["application/problem+json"] = new() { Schema = problem } }, + Content = new Dictionary { ["application/problem+json"] = new OpenApiMediaType { Schema = problem } }, }; touched = true; } @@ -174,7 +180,7 @@ private static (int Status, int Range) Rank(string key) => /// 's gets them from as well. A $ref under /// application/problem+json to a type that is no problem is left alone. Null where no content is a problem. /// - private static List? DeclaredProblems(OpenApiOperationTransformerContext context, int status, IDictionary content) + private static List? DeclaredProblems(OpenApiOperationTransformerContext context, int status, IDictionary content) { var problems = context.Description.SupportedResponseTypes .Where(declared => declared.StatusCode == status && declared.Type is { } type && typeof(ProblemDetails).IsAssignableFrom(type)) diff --git a/src/CodoMetis.TypeKit.AspNetCore/README.md b/src/CodoMetis.TypeKit.AspNetCore/README.md index 97b8d98..60c6dea 100644 --- a/src/CodoMetis.TypeKit.AspNetCore/README.md +++ b/src/CodoMetis.TypeKit.AspNetCore/README.md @@ -48,7 +48,7 @@ Calling it again for a document that already has it changes nothing. **Good to know** -- **Reference `Microsoft.AspNetCore.OpenApi` at 10.0.12 or later.** This package depends on that +- **Reference `Microsoft.AspNetCore.OpenApi` at 10.0.12 or later on .NET 10, and at 11.0.0 or later on .NET 11.** This package depends on that version, and an earlier direct reference fails to restore with NU1605 (a package downgrade). - **Reference it directly.** The switch for its source generator is imported only for a direct reference. A host that gets the package only through this one fails with CS9137 ("the feature diff --git a/test/CodoMetis.TypeKit.AspNetCore.Tests/CodoMetis.TypeKit.AspNetCore.Tests.csproj b/test/CodoMetis.TypeKit.AspNetCore.Tests/CodoMetis.TypeKit.AspNetCore.Tests.csproj index 75a4479..45bf2e4 100644 --- a/test/CodoMetis.TypeKit.AspNetCore.Tests/CodoMetis.TypeKit.AspNetCore.Tests.csproj +++ b/test/CodoMetis.TypeKit.AspNetCore.Tests/CodoMetis.TypeKit.AspNetCore.Tests.csproj @@ -1,4 +1,9 @@ + + + + net10.0;net11.0 +