Skip to content

[9.0] Fix Last() on primitive collections returning the first array element - #3957

Merged
roji merged 1 commit into
hotfix/9.0.5from
roji-primitive-collection-last-9-0-backport
Oct 14, 2026
Merged

roji merged 1 commit into
hotfix/9.0.5from
roji-primitive-collection-last-9-0-backport

Conversation

@roji

@roji roji commented Oct 14, 2026

Copy link
Copy Markdown
Member

Summary

Backport of #3925 (reviewed head 32c2baac5209aaebade01d5ef287db3d9fb0a2fa), addressing #3909.

  • Preserve descending ordinality and WITH ORDINALITY for Last()/LastOrDefault() while retaining ascending-order cleanup for First().
  • Include the source PR's else if fix copying later retained tables into the lazily allocated table array.
  • Add the two regression tests, adapted only to EF 9's sync/async test API and entity projection. No other query behavior changes.

Validation

  • Both new regression tests reproduced the bug before the production change, in sync and async modes (4 failures: expected 2 matching rows, actual 0).
  • After the fix, all 26 targeted cases passed: new Last/LastOrDefault, existing First/FirstOrDefault, SelectMany variants, joins, Concat, Union and Distinct.
  • Final functional-test project build succeeded with 0 warnings and 0 errors.

Validated with session-local .NET SDK 9.0.312 and PostgreSQL 18.4 using an isolated test database. The temporary fixture database-name override was removed before commit.

…lement

Backport #3925, including retained-table copying, and adapt Last/LastOrDefault regressions to the 9.0 async test API.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: a1fb0d48-c667-44a2-849d-7cf03dec429c
@roji
roji merged commit 27a5efc into hotfix/9.0.5 Oct 14, 2026
10 checks passed
@roji
roji deleted the roji-primitive-collection-last-9-0-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