Skip to content

[8.0] Fix Last on primitive collections returning the first element - #3958

Merged
roji merged 1 commit into
hotfix/8.0.12from
roji-primitive-collection-last-8-backport
Oct 14, 2026
Merged

roji merged 1 commit into
hotfix/8.0.12from
roji-primitive-collection-last-8-backport

Conversation

@roji

@roji roji commented Oct 14, 2026

Copy link
Copy Markdown
Member

Summary

Backport of #3925 at reviewed commit 32c2baac5209aaebade01d5ef287db3d9fb0a2fa to hotfix/8.0.12, addressing #3909.

  • Preserve descending ordinality ordering and WITH ORDINALITY for primitive-collection Last() / LastOrDefault(); ascending ordinality cleanup is unchanged.
  • Include the source PR's else if fix that copies retained tables into the lazily allocated table array.
  • Backport both regression tests, adapting them to EF 8's sync/async theory pattern and entity projection. No other behavior changes.

Validation

  • Both regression tests failed before the production fix, in sync and async mode (expected two matching rows, got zero).
  • Passed 26 isolated cases on PostgreSQL 18.4 with .NET SDK 8.0.425 / EF Core 8.0.11: four Last/LastOrDefault cases, four temporary First/FirstOrDefault compatibility checks, and 18 existing join/collection cases.
  • Passed a final 23-case run of the committed regressions, existing join/collection cases, and test-override check.
  • Final committed sources build with zero warnings and errors.

EF 8 lacks the newer inherited primitive-collection First/FirstOrDefault tests, so equivalent query/SQL checks were used only for local validation. Those checks and the temporary branch-specific test-store override were removed before committing; no fixture-isolation changes are included.

Backport #3925 at 32c2baa, including retained-table copying and the Last/LastOrDefault regression tests adapted to EF 8 APIs.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: ea931961-9d81-454e-8f33-6a80c71febad
@roji
roji merged commit cc35c61 into hotfix/8.0.12 Oct 14, 2026
9 checks passed
@roji
roji deleted the roji-primitive-collection-last-8-backport branch October 14, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Last()/LastOrDefault() on primitive collections is translated like First() — missing descending ordinality ordering

1 participant