Skip to content

A member of a value object that can be null, or is an enum, is read as the column - #275

Merged
CaffeinatedCoder merged 7 commits into
mainfrom
claude/angry-wright-1c6f7b
Nov 29, 2026
Merged

CaffeinatedCoder merged 7 commits into
mainfrom
claude/angry-wright-1c6f7b

Conversation

@CaffeinatedCoder

@CaffeinatedCoder CaffeinatedCoder commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Closes #261
Closes #262
Closes #270
Closes #271

Problem

All four are about the member a value converter stores, x.Email.Value where the converter is written as e => e.Value (#222).

5.x refused #261's lambda too (read from its source at v5.6.0, not run), so no 5.x snapshot holds such a path.

Change

  • The translator (LambdaTranslator.PathTo): Value of a Nullable<T> is no segment of a path. One place builds a path from a member chain now, for the dispatch and for the nullability check.
  • The resolver (PropertyPaths.ConvertedMember): a converter's access to its member may go through the nullable's value, v => v.Value.Value. The walk hands the converter's own access on (Walked.Stored). The resolver still takes no Value of a nullable in a path.
  • The model's facts (ModelFacts): a member that is its property's whole column answers for itself.
    • StoredLiteral: the value is made the member's type, the conversions the converter has around the member are done to it (EF Core adds the enum's to its number: the mapping's converter is g => Convert(g.Value, Int32)), and the mapping writes the result with GenerateProviderValueSqlLiteral.
    • KeepsOrder: the rule it had, asked of the member's type. An enum member stored as its number keeps its order.
    • IsBooleanColumn: a boolean member that is stored as it is, is a boolean column.
  • The translator asks StoredLiteral only where it has no literal of its own (ValueOfTheModelAlone): for an enum, and for a value of a type the spelling does not write, such as a Guid. Both were refused through a member. A stored flag without a value to compare with is refused, where it was written without one.

What changes for an input main took. Three shapes, and nothing else:

  1. A member of a nullable struct complex property is refused, and one beside a member named Value is read from another column #270, the wrong column. Over a complex property that can be null whose struct has a complex property of its own named Value, x.O.Value.B resolves to O_B where it resolved to O_Value_B. The first migration after the upgrade drops and creates the object (What_was_stored_wrongly_is_dropped_and_created_as_the_lambda_says).
  2. A boolean member of a value object as a condition by itself is stored without the value it compares with #271, a boolean member as a condition, in every form: x.Used.Value, !x.Used.Value, !!x.Used.Value, and each beside another condition with && or ||. All were stored with "Used" = and nothing behind the sign, which no server takes; each is "Used" or NOT ("Used") now, and a drop and a create from a snapshot that holds the old text (the same test, and five rows of Vouchers.Members).
  3. A stored path that moved, for the same object. Over a complex property that can be null whose struct has a value object as its own member Value, x.W.Value.Value was stored as the path W.Value.Value, the member the converter stores, and is W.Value, the property. For a declaration without a name the key moves with the path. Both are the one column: a model stored the old way diffs to nothing against the model as it is bound now, both ways, from the model and from its compiled snapshot (A_path_stored_with_the_nullables_value_in_it_is_the_same_object, which also holds that the two keys differ).

No resolver method answers otherwise for a path it took, and no epoch is touched: what changed is the path the translator hands on, and a snapshot holds the path, not the lambda. A value the translator has a literal for is stored through a member as the text main stores, for a string, a boolean, a decimal, a double and a float (A_value_the_translator_writes_is_written_through_a_member_as_before, which passes with the three source files as on main).

Left open, as #272: a value the spelling has a literal for is still written by the spelling through a member, {Price.Value} = 5, where the mapping writes 5.0 for the same comparison on the property. Handing every value to the mapping moves a stored condition, so it is a decision and not part of this.

Not touched: the catalog verifier's files, the READMEs, the smoke test.

Tests

  • ModelFactsBindingTests (PostgreSQL package), a new model of value objects (Harness/ValueObjectModels.cs), eleven conditions:
    • each condition's bound template;
    • the oracle: EF Core has no query for a member of a converted property, which the test holds first for every row. Eight rows are compared with EF Core's query for the same comparison on the property, x.Rank == new VoucherRank(…). An order through a member and a boolean member by itself have no query on the property either, and are held as text;
    • the model against the snapshot EF Core scaffolds for it: no operations both ways, and the statements;
    • keys through a nullable's value: an expression, the member by itself, a member of a complex property;
    • the refusal where the member is not what the column holds, a converter written as a call and an enum stored as its name: it names the comparison on the property. This one passes without the change too: it is A member of a value object is refused when a library wrote its converter as a method call #248's refusal, held here for an enum.
  • SchemaResolverTests, on Npgsql, SQL Server and SQLite, model and snapshot: paths below a struct that can be null with both forms of converter, a complex property that can be null, and the lambdas through the translator, the two rows of A member of a nullable struct complex property is refused, and one beside a member named Value is read from another column #270 among them. And the converter's twin of A member of a nullable struct complex property is refused, and one beside a member named Value is read from another column #270: d => d.Value.Text over a struct with members Value and Text of its own is refused as a converter written otherwise, for Dial.Text and for Dial.Value; the snapshot takes the member, as behind any converter.
  • After the review, in ModelFactsBindingTests: the text a value is stored as through a member, beside EF Core's query on the property, which is 5.0 for the decimal and the double and so pins what A value compared with a member of a value object is written by the spelling, not by the property's mapping #272 would move; the stored path that moved; the two shapes that are rebuilt.
  • The parity sweep has an operand that is a member of a struct that can be null, x.Place!.Value.City, for which EF Core has a query. Every row over it agrees with EF Core's SQL but ten, which are the rows the block "Concatenation with a value that is not a string" already waives over a column, and are listed there.
  • LambdaTranslatorTests: the paths, the null compensation of a member of a struct that can be null, and a stored flag without a value.
  • SpellingParityTests (second provider): the same facts on SQL Server, against its queries for the property. There a boolean member by itself is [Done] = CAST(1 AS bit), which is also what EF Core writes for the property.

Without the subject, one break at a time, each restored and rebuilt:

Break What failed
The nullable's Value is a segment again 5 kernel tests ({Nick.Value.Value} for {Nick.Value}), 4 PostgreSQL, 1 second provider: "The path 'Nick.Value.Value' on Voucher goes past …"
A converter's access has to be on the parameter itself 6 kernel, 3 PostgreSQL, 1 second provider: "The path 'Alias.Value' on Parcel goes past the property 'Alias' …"
The model writes no value of a member 3 PostgreSQL, 1 second provider: "The expression 'Convert(x.Rank.Value, Int32)' compares an enum"
A member's order is asked of the property's type 3 PostgreSQL: "The comparison '(Convert(x.Rank.Value, Int32) > 0)' orders by 'Rank.Value' …"
A boolean member is no boolean column 3 PostgreSQL, 1 second provider: "The expression 'x.Used.Value' has no translation in a declaration's predicate"
A stored flag without a value is written A_stored_flag_without_a_value_to_compare_with_is_refused: no exception was thrown
The converter's conversions are not done to the value 3 PostgreSQL, 1 second provider: {Rank.Value} = Closed for {Rank.Value} = 1
The value is not made the member's type 3 PostgreSQL, 1 second provider: "A value compared with 'Rank.Value' on Voucher cannot be written as that column stores it"

| After the review: every value through a member goes to the mapping | A_value_the_translator_writes_is_written_through_a_member_as_before alone: {Price.Value} = 5.0 for = 5 |
| Any member named Value is looked through in a converter | A_structs_own_member_named_Value_is_not_looked_through_in_a_converter on the three providers: no "This converter is written otherwise" |
| The nullable's Value is a segment again (run again) | now also the sweep, with 125 rows that disagree, A_path_stored_with_the_nullables_value_in_it_is_the_same_object and What_was_stored_wrongly_… |
| A boolean member is no boolean column (run again) | now also What_was_stored_wrongly_… |

The conditions of ModelFactsBindingTests are one model, so a break that fails the binding fails its three tests together; the message says which condition.

Run locally at the head of this branch, main (11158ac) merged in:

  • dotnet build CodoMetis.EFCore.SchemaKit.slnx: no warnings, no errors.
  • Without a server: the kernel's tests, 923 passed, 4 skipped; the parity sweep is among them, all eight of its tests, the checked-context run included, and no waiver is unused. The PostgreSQL package's: 500 passed, 268 skipped. The second provider's: 95 passed, 86 skipped. The cross-tests with ValueRanges: 28 passed, 12 skipped. The probes: 127 passed. Spike F: 45 passed.
  • On PostgreSQL 18.6, at 2115b79 (main at a130508 merged in), in a container of this session's own, started with the user's approval and removed after the run: the kernel's tests of category Integration, 4 passed, the live parity sweep among them (Translated_predicates_and_expressions_answer_on_postgres_as_ef_cores_queries_do), which runs the ten new rows waived as "same"; and the PostgreSQL package's, 264 passed.
  • At b8068e2, before main was merged in, and not run again: spike B without SPIKE_PG, every path as expected; spike D, every measured cell as its table says, 14 pairs of a consumer and a server not measured; spikes E and G all skipped, since each needs a server.

Not run: anything on PostgreSQL 16 or on SQL Server, the consumer smoke test, and the live paths of spikes B, D, E and G. They are CI's lanes for this pull request.

Seen in the review and filed: x.Place.HasValue and x.Place != null on a complex property that can be null are refused, where EF Core writes "Place_City" IS NOT NULL (#279). The same on main, and not part of this.

For the review

🤖 Generated with Claude Code

CaffeinatedCoder and others added 2 commits November 29, 2026 11:26
…ead as the column

The value of a Nullable<T> is no segment of a path any more: x.Nick.Value.Value
over a struct that can be null is the path Nick.Value (#261), and a member of a
struct mapped as a complex property is read where the lambda reads it (#270). A
converter written on such a property, v => v.Value.Value, names its member.

A value compared with the member a converter stores is written by the property's
mapping where the translator has no literal of its own: an enum as the column
stores it (#262). The member's order and whether it is a boolean column are
asked of the member, so a boolean member by itself is a condition (#271).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The changelog's preview.3 section, the guide's section on a member of a value
object and CLAUDE.md say what #261, #262, #270 and #271 changed, and what
#272 leaves open.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Nov 29, 2026
@CaffeinatedCoder CaffeinatedCoder added enhancement New feature or request package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) area/expression-indexes Expression, typed lambda and JSON member indexes labels Nov 29, 2026
@CaffeinatedCoder

Copy link
Copy Markdown
Owner Author

Review at 915b8aa: an independent reviewer (offline, two copies made with git archive, main at 0d7ac39 against this head), read and checked by the coordinating session. No server was available, so nothing below was applied to a database.

Verdict: no silent wrong answer was found. About fifty shapes of the newly accepted lambdas were tried (the member on the right, inside !, inside && and ||, against another column, a captured enum, a Guid member, a member not named Value, as a key and in INCLUDE, below a complex property): each that has a twin on the property matches EF Core's query for it, on PostgreSQL and on SQL Server, and each model diffs to nothing against its snapshot, both ways. With the three source files as on main, every new test fails but the one the description says passes either way. A real segment named Value is not dropped: a seed that drops any Value fails eleven tests.

Before the merge, five things:

  1. Missing test: the text a value compared through a member is stored as. ValueOfTheModelAlone returns null for a value the spelling writes itself, which is what keeps x.Price.Value == 5m stored as {Price.Value} = 5, as on main. With that line changed so that every value through a member goes to the mapping, the condition is {Price.Value} = 5.0, the next migration rebuilds the index, and all offline tests of the three projects pass. The rows of Vouchers.Members marked "As they were" are a string and a bool, which both writers write alike. Wanted: rows for a decimal, a double and a float member compared with a constant, each with the text main stores. That is also what A value compared with a member of a value object is written by the spelling, not by the property's mapping #272 would have to move on purpose.

  2. Missing test: the converter's twin of A member of a nullable struct complex property is refused, and one beside a member named Value is read from another column #270. In ConvertedMember.ReadFrom, Nullable.GetUnderlyingType(value.Member.DeclaringType!) is not null is what keeps a converter d => d.Value.X, over a struct with members Value and X of its own, from being taken as one that stores X. With the check removed, pg.Unique(x => x.D2.X) scaffolds CREATE UNIQUE INDEX … ("D2"), a unique index on another member than the lambda names, and all offline tests pass. Wanted: that converter in SchemaResolverTests, on the model and on its snapshot, with D2.X refused as a converter written otherwise.

  3. What changes for an input main took is more than the two cases listed. Say all of it in the description and in the changelog's "Changed":

    • A boolean member of a value object as a condition by itself is stored without the value it compares with #271 in every form, not only the member by itself: x.Used.Value && …, !x.Used.Value || … and !!x.Used.Value were stored with "Used" = and are a drop and a create from a snapshot main wrote. (None of them was a statement a server takes.)
    • A struct complex property that can be null whose own member Value is a converted value object: x.W!.Value.Value == … was stored as the column path W.Value.Value and is W.Value; for a key without a name the declaration's key moves with it. Measured as harmless: the same SQL, and a snapshot main wrote diffs to nothing against the model, both ways. It is still a stored path and a stored key that moved, and the description says "nothing changes … with two exceptions". If you can hold it in a test (the snapshot with the old path against the model, no operations both ways), do.
  4. Wording. The changelog entry for A member of a nullable struct value object is refused, also when its converter is written as the member #261 and the guide's "A value object that can be null" say x.Nick!.Value.Value != "none" keeps the rows without a nick "as C# does". In C# Nullable<T>.Value throws for such a row. What the SQL matches is EF Core's query for x.Nick != new Tag("none"): say that. And the guide says "the lambda throws" for a generated converter or an enum stored as its name: it is the model's build that throws.

  5. The parity sweep does not reach the new path. ParityCatalogue.Operands() has no struct complex property that can be null, and for that one EF Core has a query: x.Place!.Value.City != "a" is p."Place_City" <> 'a' OR p."Place_City" IS NULL. Such an operand would sweep PathTo across every construct. Add it, or say on the pull request why not and file it.

Also: main moved (#269, #273, #274 are merged; it is at a130508) and this branch now conflicts in CHANGELOG.md, where ### Fixed is new. Merge main in.

Seen and not asked for here: x.Place.HasValue and x.Place != null on a complex property that can be null are refused, where EF Core writes "Place_City" IS NOT NULL. A refusal, the same on main; an issue of its own if it is worth one.

CaffeinatedCoder and others added 2 commits November 29, 2026 12:08
Rows for a decimal, a double and a float compared through a member, with the
text 11.0.0-preview.2 stores and what EF Core writes on the property (#272).
A converter over a struct's own member named Value is not looked through. A
path stored with the nullable's Value in it is the same object, and the two
shapes that were stored wrongly are rebuilt. The parity sweep has an operand
that is a member of a struct that can be null. The changelog and the guide say
every input that is stored otherwise, and no longer say "as C# does".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@CaffeinatedCoder

Copy link
Copy Markdown
Owner Author

The review's five points are in 2115b79, on top of main at a130508 (merged in as 03865d4). The description above is rewritten for them.

  1. The text a value is stored as through a member. A_value_the_translator_writes_is_written_through_a_member_as_before holds a string, a boolean, a decimal, a double and a float, each with what is stored and with EF Core's query on the property (5.0 for the decimal and the double, 5 for the float). With every value through a member handed to the mapping, it alone fails, on {Price.Value} = 5.0. With the three source files as on main it passes: the text is what main stores.
  2. The converter's twin of A member of a nullable struct complex property is refused, and one beside a member named Value is read from another column #270. A_structs_own_member_named_Value_is_not_looked_through_in_a_converter, on the three providers: d => d.Value.Text over Dial(Stamp Value, string Text) is refused as a converter written otherwise, for Dial.Text and Dial.Value; the snapshot takes the member, as behind any converter. With the check on the declaring type removed, it fails on all three.
  3. Every input that is stored otherwise is in the description and in the changelog, under "Changed" for the path that moved and under "Fixed" for the two that are rebuilt. A_path_stored_with_the_nullables_value_in_it_is_the_same_object holds the moved path, the model and its compiled snapshot both ways, and that the unnamed declaration's key differs; What_was_stored_wrongly_is_dropped_and_created_as_the_lambda_says holds the drop and the create for A member of a nullable struct complex property is refused, and one beside a member named Value is read from another column #270 and A boolean member of a value object as a condition by itself is stored without the value it compares with #271; five rows of Vouchers.Members hold A boolean member of a value object as a condition by itself is stored without the value it compares with #271 in its forms.
  4. Wording. "As C# does" is gone from the changelog, the guide and a test's comment: the SQL is what EF Core's query writes for the comparison on the property. The guide says the model fails to build.
  5. The sweep has the operand x.Place!.Value.City. Ten of its rows fall under the block that waives the same rows over a column, and are listed there; every other row agrees with EF Core. With the nullable's Value a segment again, 125 rows disagree. The live sweep was run on PostgreSQL 18.6 and passes.

x.Place.HasValue and x.Place != null are #279.

CaffeinatedCoder and others added 2 commits November 29, 2026 12:31
The review commit replaced the two bullets it rewrote up to the next heading,
and took the one behind them with it. #266 is open and the bullet is as true
as it was.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@CaffeinatedCoder

Copy link
Copy Markdown
Owner Author

The guide's bullet on #266 went by accident and is back in 7cc8a9b. The review commit rewrote the two bullets in front of it with a replacement that ran to the next heading, and took the one behind them with it. #266 is open and nothing here makes the bullet untrue. Compared with main (11158ac, merged in as 08751bf), the guide now loses no line: the difference is the one sentence under "Conditions" and the two bullets this pull request adds.

@CaffeinatedCoder
CaffeinatedCoder merged commit 9d63e75 into main Nov 29, 2026
12 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the claude/angry-wright-1c6f7b branch November 29, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/expression-indexes Expression, typed lambda and JSON member indexes enhancement New feature or request package/core Affects CodoMetis.EFCore.SchemaKit (the kernel)

Projects

None yet

1 participant