Repository navigation
Bulk operations: accept the auto-include wrapper over entities with included navigations (Fixes #69) - #113
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
ClassifyBulkSourcerefused it with "The 'Select' operator is not supported in a bulk delete or update", an operator the caller never wrote.#69 reported
ExecuteUpdateon EF9. Measured while fixing it, the real scope is wider:ExecuteUpdate, owned orAutoIncludenavigationExecuteDelete, owned orAutoIncludenavigationSo
ExecuteDeleteover any entity with an owned navigation was unusable on every supported version. TheAutoInclude(false)workaround named in the issue also makes plain queries return the owned navigation asnullunless they callInclude, so it was not a good answer.Fix
MongoNonQueryExpression.UnwrapBulkOperatoralready strips theExecuteXmarker. 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 tosource.The wrapper only loads related data, so it cannot change which documents match, and a bulk operation returns none of it.
Still refused, deliberately:
Join: it can drop documents whose reference dangles, which would change the affected set.Whereabove the join (a predicate on the navigation, already unsupported) and any otherSelect.Tests
BulkOperationsOwnedNavigationTests(39 tests, EF9/EF10/EF11, sync and async):OwnsOne,OwnsMany, nested owned (including a row with a null owned reference), TPHOfTypeof 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.NonSharedModelBulkUpdatesMongoTestoverrides that asserted the old failure now callbase(upstream'sDelete_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 twoUpdate_non_owned_property_on_entity_with_owned*). The EF9-only branch ofComplexTypeRobustnessTestsis gone.docs/failing-spec-tests.mdcounts 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.