Repository navigation
test: round-trip every type in a JSON column through a compiled model - #211
Merged
Merged
Conversation
CompiledModelJsonTests generates the compiled model `dotnet ef dbcontext optimize` writes for a context holding every discovered range, multirange and value set type inside a jsonb document (52 types today, floor 48), compiles it with Roslyn in-process, loads it, and holds it to the runtime model on a live server: the reader/writer each model uses, the document text each writes, and the value the compiled model reads from its own row and from a runtime-written one. 148 values, all agree. Microsoft.EntityFrameworkCore.Design (test-only) brings the generator and Roslyn. The standard compiled model carries no type mappings and resolves them through the plugin at run time, so the JSON reader/writers' ConstructorExpression is never consulted; only the Native AOT form is, and generating that fails because the plugin's mappings have no static Default (#209, opened from this work). A reader/writer that throws for one type fails the test ("TimeRange: saving failed"). Closes #43 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #43
Problem
The JSON-column readers and writers point
ConstructorExpressionat a staticInstance"so compiled models can use them". That was checked once, by hand, withdotnet ef dbcontext optimizein the 9.0.0 review, and nothing has guarded it since.Change
New
CompiledModelJsonTestsin the integration project:The context. It holds every discovered range, multirange and value set type inside a
jsonbdocument, one table each: 52 types today, with a floor of 48. Types come fromFuzzTypes, so a new type is covered without an edit.The compiled model. It is generated in-process the way
dotnet ef dbcontext optimizedoes it (DesignTimeServicesBuilder, then the C# compiled-model generator), compiled with Roslyn against the loaded assemblies, loaded, and passed toUseModel.The comparison runs on a live server, with the runtime model as the oracle:
That's 148 values, and all agree.
The values: a range's five shapes, a multirange's empty, five-shape and gapped sets, and a set's empty and probe sets.
Microsoft.EntityFrameworkCore.Design10.0.0 is a new test-only reference; it brings the generator and Roslyn. The test's types live in a namespace of their own, because the generated code imports every namespace it names and this assembly has twoAuditStampand twoBillingMonthtypes. The EF1001 pragma is file-level, with its reason.What I found: #209 (opened under #58)
ConstructorExpression.dbcontext optimize --nativeaot, which--precompile-queriesneeds).The type mapping used is incompatible with a compiled model. The mapping type must have a 'public static readonly ValueRangeTypeMapping<DateRange, DateOnly> … Default' property.So the public
Instancedesign has never run. I wrote twoConstructorExpressionseeds: one the generated code couldn't construct, and one pointing YearMonth at a sibling'sInstance.oracles.cs seedsshowed both MISSED by this test, as expected, so I didn't keep them or register the test as an oracle. They are in #209's body, for when the Native AOT form works.Tests
TimeRangegivesTimeRange: saving failed: seeded;🤖 Generated with Claude Code