Skip to content

fix: keep EF Core's _ord column an integer in the empty-root rewrite (#319) - #389

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
fix/319-ord-cast
Oct 24, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
fix/319-ord-cast

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #319

Problem

EmptyCollectionRewriter casts every NULL constant of EF Core's empty query root that has a registered range or value set CLR type. EF Core types its _ord ordering column the same way as the elements, so _ord was cast to the range type too:

SELECT NULL::int4range AS _ord, NULL::int4range AS "Value"
WHERE FALSE

When the list has elements, _ord is an integer (VALUES (0, @p1), …). No answer changed: no row exists, and ORDER BY over a range NULL is valid. But a shape comparing _ord with an integer would fail on the server, and only for the empty list.

Change

  • EmptyCollectionRewriter: the _ord projection becomes 0. That's an integer, as it is when the list has elements, and as OneRowOfNulls writes it on release/10.x. Only the element column is still cast. The class remarks say so.
  • A ### Fixed row in the root changelog and the EF Core package's changelog, under 11.0.0-preview.1.

Tests

  • RangeCollectionTranslationTests.FirstOrDefault_OverAnEmptyCapturedList_KeepsTheOrderingColumnAnInteger pins the whole statement for empty.Where(w => w.Overlaps(b.Seats)).FirstOrDefault(). Before the fix it fails with actual: … SELECT NULL::int4range AS _ord …; with the fix it passes.
  • Every suite outside the integration projects passes: unit, NodaTime, EF translation, AspNetCore and conventions.
  • Live, on PostgreSQL 16: RangeCollectionContainsTests, SetCollectionContainsTests and CapturedCollectionProbeTests (28 tests).

The 10.x port is #325, for 10.2.0 (#358).

🤖 Generated with Claude Code

…319)

EF Core types the _ord ordering column of its empty query root like the
elements, so TypeTheNulls cast it to the range type with them
(NULL::int4range AS _ord). It is an integer when the list has elements,
so a shape comparing it with one would fail on the server for the empty
list only. Write it as 0, as OneRowOfNulls does on release/10.x.

Found-By: RV
Defect-Class: SQL

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Oct 24, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working area/range-set RangeSet and multirange algebra area/value-sets Value set families and wrapper arities package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime severity/low Cosmetic, message or documentation-level difference labels Oct 24, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 4b21366 into main Oct 24, 2026
11 of 13 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/319-ord-cast branch October 24, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/range-set RangeSet and multirange algebra area/value-sets Value set families and wrapper arities bug Something isn't working package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

main: the empty-root rewrite casts EF Core's _ord column to the range type (NULL::int4range AS _ord)

1 participant