Skip to content

Bulk operations: accept the auto-include wrapper over entities with included navigations (Fixes #69) - #113

Merged
ajcvickers merged 1 commit into
releasefrom
issue-69
Nov 14, 2026
Merged

ajcvickers merged 1 commit into
releasefrom
issue-69

Conversation

@ajcvickers

Copy link
Copy Markdown
Owner

Fixes #69.

Problem

An entity type with an included navigation could not be the source of a bulk operation. Navigation expansion leaves the Include as the outermost operator of the captured chain, and ClassifyBulkSource refused it with "The 'Select' operator is not supported in a bulk delete or update", an operator the caller never wrote.

#69 reported ExecuteUpdate on EF9. Measured while fixing it, the real scope is wider:

EF9 EF10 EF11
ExecuteUpdate, owned or AutoInclude navigation failed worked worked
ExecuteDelete, owned or AutoInclude navigation failed failed failed

So ExecuteDelete over any entity with an owned navigation was unusable on every supported version. The AutoInclude(false) workaround named in the issue also makes plain queries return the owned navigation as null unless they call Include, so it was not a good answer.

Fix

MongoNonQueryExpression.UnwrapBulkOperator already strips the ExecuteX marker. It now also strips the auto-include wrapper, so every reader of the source chain (classifier, filter builder, two-phase id query, null-element scan) sees the same chain. Two shapes, matched narrowly:

  • Select(e => Include(e, ...)): an owned (embedded) navigation.
  • LeftJoin(source, DbSet<Related>, ...) + Select(ti => Include(ti.Outer, nav, ti.Inner)): a reference navigation to another collection, any number of them (nested). Stripped to source.

The wrapper only loads related data, so it cannot change which documents match, and a bulk operation returns none of it.

Still refused, deliberately:

  • A required navigation's inner Join: it can drop documents whose reference dangles, which would change the affected set.
  • Collection includes, a Where above the join (a predicate on the navigation, already unsupported) and any other Select.

Tests

  • New BulkOperationsOwnedNavigationTests (39 tests, EF9/EF10/EF11, sync and async): OwnsOne, OwnsMany, nested owned (including a row with a null owned reference), TPH OfType of a derived type that owns a navigation, query filters, Skip/Take (two-phase), and cross-collection includes with an orphan foreign key (the orphan is still affected and the related documents are never touched). Each test reads the collection back through a fresh context. The refused shapes assert that they still throw and delete nothing.
  • Without the fix, 12 of these fail on EF10 and 24 on EF9.
  • Six NonSharedModelBulkUpdatesMongoTest overrides that asserted the old failure now call base (upstream's Delete_entity_with_auto_include, Delete_aggregate_root_when_eager_loaded_owned_collection, Delete_aggregate_root_when_table_sharing_with_owned, Delete_with_owned_collection_and_non_natively_translatable_query, and on EF9 the two Update_non_owned_property_on_entity_with_owned*). The EF9-only branch of ComplexTypeRobustnessTests is gone. docs/failing-spec-tests.md counts updated (EF-X016: 61 to 55).
  • /test-all (EF8-EF11, Default and NativeOnly, unit + functional + spec): all 24 projects pass, 0 failures, encryption tests ran.

Not a breaking change: shapes that threw now work.

…ncluded navigations (Fixes #69)

Navigation expansion leaves the Include of an included navigation as the outermost
operator of the captured source chain. The bulk-source classifier rejected it as
"The 'Select' operator is not supported in a bulk delete or update", although it
only loads related data and cannot change which documents match.

Affected: ExecuteUpdate and ExecuteDelete on EF9, and ExecuteDelete on EF10 and EF11
(ExecuteUpdate on EF10+ already dropped it, which is why #69 only showed EF9). Any
entity type with an owned navigation (auto-included by convention) or an AutoInclude
reference navigation hit it.

MongoNonQueryExpression.UnwrapBulkOperator now also strips, narrowly:
- Select(e => Include(e, ...)) for embedded (owned) navigations, and
- LeftJoin(source, DbSet<Related>, ...) + Select(ti => Include(ti.Outer, nav, ti.Inner))
  for reference navigations to another collection (any number, nested).
Every reader of the chain (classifier, filter builder, two-phase id query, null-element
scan) goes through that method. Not stripped, so still refused: a required navigation's
inner Join (it can drop documents whose reference dangles), collection includes, a Where
over the join (a predicate on the navigation) and any other Select.

Tests: BulkOperationsOwnedNavigationTests (39) over OwnsOne/OwnsMany/nested owned, TPH
with an owned derived type, query filters, Skip/Take (two-phase), sync and async, and
cross-collection includes with an orphan foreign key; the refused shapes assert they
still throw and delete nothing. Six NonSharedModelBulkUpdatesMongoTest overrides that
asserted the old failure now call base, and the EF9 branch of
ComplexTypeRobustnessTests is gone. Inventory counts in docs/failing-spec-tests.md
updated (EF-X016: 61 -> 55).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.

EF9: ExecuteUpdate fails on any entity with an auto-included owned navigation

1 participant