Skip to content

Conversation

@roji
Copy link
Member

@roji roji commented Jan 12, 2026

Fixes #37478
Simplified/targeted backport of: #37482

Description

As part of the JSON complex type work in 10.0, the navigation expansion logic for binding properties/navigations changed; unfortunately, a bug slipped in where we no longer properly take into account inheritance subtypes.

Customer impact

Queries which perform subqueries over primitive collection properties on an inheritance subtype in EF queries now fail:

var query = context.BaseTypes
    .Where(x => ((SubType)x).Ints.Any())
    .ToArray();

This isn't an uncommon scenario, and there's unfortunately no good workaround.

How found

Customer reported on EF 10.0.0.

Regression

Yes.

Testing

Test added.

Risk

Very low. The fix is very targeted and in code modified in 10.0, quirk added.

@roji roji requested a review from artl93 January 12, 2026 15:43
@roji roji requested a review from a team as a code owner January 12, 2026 15:43
Copilot AI review requested due to automatic review settings January 12, 2026 15:43
@roji roji changed the title [release/10.0] Fix primitive/complex collection handling on subtypes (10.0) [release/10.0] Fix primitive/complex collection handling on subtypes Jan 12, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a regression introduced in EF Core 10.0 where queries over primitive collections or complex types on inheritance subtypes fail to translate. The issue occurred when the JSON complex type work changed navigation expansion logic without properly handling inheritance scenarios.

Changes:

  • Added quirk flag UseOldBehavior37478 to enable opt-out behavior for backwards compatibility
  • Fixed type resolution in NavigationExpandingExpressionVisitor to check inheritance hierarchy when accessing primitive collections and complex properties on derived types
  • Added comprehensive test coverage across multiple providers (base specification test, SQL Server, and Cosmos)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs Added quirk flag and type resolution logic to properly handle inheritance when expanding primitive collections and complex properties
test/EFCore.Specification.Tests/Query/NonSharedPrimitiveCollectionsQueryTestBase.cs Added base test case with inheritance scenario to verify subtype primitive collection access works
test/EFCore.SqlServer.FunctionalTests/Query/NonSharedPrimitiveCollectionsQuerySqlServerTest.cs Added SQL Server-specific test override with SQL assertion for OPENJSON query
test/EFCore.Cosmos.FunctionalTests/Query/NonSharedPrimitiveCollectionsQueryCosmosTest.cs Added Cosmos-specific test override with assertion for ARRAY_LENGTH query

Copy link
Member

@artl93 artl93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Customer reported regression against the latest version with targeted, quirked fix. Approved for me.

@roji roji merged commit 540d01a into dotnet:release/10.0 Jan 12, 2026
12 of 13 checks passed
@roji roji deleted the Backport37478 branch January 12, 2026 20:54
@AndriySvyryd AndriySvyryd added this to the 10.0.3 milestone Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can no longer translate operators over primitive collections or complex types on inheritance subtypes

3 participants