Query: whole non-entity object from a plain (non-aggregated) LeftJoin/DefaultIfEmpty inner is not nulled on no-match
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
Research direction
Start with the navigation-expansion rework in #32957/#37859 and trace how PendingSelector is folded before AddJoin. Reproduce the plain non-aggregated Select with LeftJoin or GroupJoin plus DefaultIfEmpty, then compare it with the optional-navigation and other #22517 cases. Done means the no-match whole object is null without regressing optional-navigation compensation.
Written by the indexing model from the issue text.
Description
Sub-case of #22517. Prior report: #26873 (closed as duplicate). This one is filed to track the specific plain-inner variant, which — unlike its siblings — cannot be fixed with the narrow relational marker and should be tackled as part of the navigation-expansion rework (#32957 / #37859).
Repro shape
A whole non-entity object projected from the nullable side of a LeftJoin / GroupJoin+DefaultIfEmpty, where the inner is a plain (non-aggregated) Select:
var categories = context.Requests.Select(r => new { r.PickupStatusId, Count = 1 });
var query = context.Statuses
.LeftJoin(categories, s => s.PickupStatusId, c => c.PickupStatusId, (s, countInfo) => new { s.PickupStatusId, countInfo });
On a no-match row this throws Nullable object must have a value instead of yielding a null countInfo. Same shape via GroupJoin + DefaultIfEmpty.
Root cause
Navigation expansion folds the trivial inner Select into the pending selector and moves the projection forward. So at AddJoin the inner shaper is the raw entity, not a New/MemberInit. The #30915 marker gate is conditioned on the inner shaper being New/MemberInit, so the marker is never injected. Nothing gates the object at materialization.
Why this cannot be fixed in the relational layer
Two relational-layer approaches were tried and rejected:
- Inject the marker at
AddJoin. The code path never runs — the inner shaper is already a bare entity by the timeAddJoinsees it. - Gate at projection-binding time instead. This false-positives on ordinary optional-navigation projections (
Select(x => new { x.OptionalNav.Prop })): it nulls the whole object instead of the member, defeating optional-navigation type compensation. Confirmed regression on 8GearsOfWarQuerytests.
After folding, the whole-DefaultIfEmpty'd-element case is structurally identical to an optional-navigation member access. The distinguishing signal is PendingSelector, which is a core-only concept, invisible to providers, and erased before translation runs. No relational-layer rule can recover it.
Conclusion
The marker gate needs the inner projection to still be a New/MemberInit at translation time; folding removes that precondition. Removing/reworking navigation expansion dissolves the fold — the projection reaches translation as written, the marker fires, and the optional-navigation case stays distinct. This variant belongs in that work, not a narrow relational fix.
The other #22517 sub-cases (struct/record-struct whole object #30915, GroupBy-after-join #28119, value-type left-join default #38555) do not fold and remain fixable narrowly; they are unaffected.
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.5k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 182
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/efcore
-
customer-reported
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
GroupBy element `OrderBy(...).First()`/`MaxBy` over an owned type mapped to its own table fails to translatePossibly taken @cincuranet claimed this today. Openarea-groupby area-query
Difficulty 4/5 3-5 days Newbie friendliness 25/100
dotnet/efcore#39833 · 1 assignee ·
Maintainers usually reply within 2 days
-
SQLite: Polygon.Length translates to GLength, which returns 0Possibly taken @cincuranet claimed this today. Openarea-query area-sqlite
Difficulty 3/5 1-2 days Newbie friendliness 45/100
dotnet/efcore#39826 · 1 assignee ·
Maintainers usually reply within 2 days
-
Migration lock with LockReleaseBehavior.Transaction doesn't prevent concurrent migrations since per-migration transactionsPossibly taken @AndriySvyryd claimed this 1 day ago. Openarea-migrations
dotnet/efcore#39824 · 1 assignee ·
Maintainers usually reply within 2 days
-
Querying a TPC base type with a JSON complex property throwsPossibly taken @cincuranet claimed this 1 day ago. Openarea-query
Difficulty 4/5 3-5 days Newbie friendliness 22/100
dotnet/efcore#39814 · 1 assignee ·
Maintainers usually reply within 2 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
SubtitleEdit/subtitleedit#17247 ·
Maintainers usually reply within 1 day
-
Restore test cleanup fails on Windows when restored files are read-onlyPossibly taken @JamBalaya56562 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
duplicati/duplicati#8046 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
Bundles Documentation
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
pyrevitlabs/pyRevit#4285 ·
Maintainers usually reply within 1 day