Skip to content

Filter required table-splitting dependents of a derived TPH type by its discriminator - #39528

Merged
AndriySvyryd merged 1 commit into
dotnet:mainfrom
jeremy-morren:fix-tph-table-splitting-dependent-filter
Nov 13, 2026
Merged

AndriySvyryd merged 1 commit into
dotnet:mainfrom
jeremy-morren:fix-tph-table-splitting-dependent-filter

Conversation

@jeremy-morren

Copy link
Copy Markdown
Contributor

Filter required table-splitting dependents of a derived TPH type by its discriminator

Fixes #39458

A required dependent sharing its table with a derived TPH type had no filter, because it has no discriminator of its own and isn't an optional dependent. Set<CatProfile>() returned a profile for every row in the table, including Dog rows. It's now filtered by the principal's discriminator, like 6.0 did, but without the join.

-- Before
SELECT [a].[Id], [a].[Note]
FROM [Animals] AS [a]

-- After
SELECT [a].[Id], [a].[Note]
FROM [Animals] AS [a]
WHERE [a].[Discriminator] = N'Cat'

Optional dependents keep their existing IS NOT NULL existence checks.

Tests: TableSplittingTestBase.Can_query_required_dependent_of_derived_type, with SQL Server and SQLite baselines.

@jeremy-morren
jeremy-morren requested a review from a team as a code owner November 4, 2026 20:06
Copilot AI balanced review requested due to automatic review settings November 4, 2026 20:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved discriminator-filtering defects can exclude valid Dog profiles or include Dog rows in Cat-only dependents across alternative principal relationships, nested dependents, and shared-view mappings.

3 open issues
What changed in this PR

Addresses #39458 by filtering required table-splitting dependents using their derived principal’s table-per-hierarchy discriminator, without adding a join.

Changes:

  • Adds principal discriminator predicates to required-dependent queries while preserving optional-dependent existence checks.
  • Adds a shared regression test verifying that querying Cat profiles excludes Dog rows.
  • Adds SQL Server and SQLite baselines for the filtered query.
File Description
src/​EFCore.Relational/​Query/​RelationalQueryableMethodTranslatingExpressionVisitor.CreateSelect.cs Adds discriminator filtering for required shared-table dependents.
test/​EFCore.Relational.Specification.Tests/​TableSplittingTestBase.cs Adds the regression model and result assertion.
test/​EFCore.SqlServer.FunctionalTests/​TableSplittingSqlServerTest.cs Verifies the SQL Server discriminator predicate.
test/​EFCore.Sqlite.FunctionalTests/​TableSplittingSqliteTest.cs Verifies the SQLite discriminator predicate.

Review effort: Balanced

…ts discriminator

Querying a required dependent that shares its table with a derived type in a TPH hierarchy returned a dependent for every row in the table, including rows of other types. Filter by the discriminator values of its principals, following required principals transitively and matching a row if any principal exists in it, like 6.0 did. This applies to view mappings as well as tables.

Fixes dotnet#39458
@jeremy-morren
jeremy-morren force-pushed the fix-tph-table-splitting-dependent-filter branch from 10af778 to a97b0c7 Compare November 4, 2026 22:12
Copilot AI balanced review requested due to automatic review settings November 4, 2026 22:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the principal-based discriminator filtering change.

1 open issue
2 resolved since last review

Review effort: Balanced

@AndriySvyryd AndriySvyryd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution!

@AndriySvyryd
AndriySvyryd merged commit 4fd472a into dotnet:main Nov 13, 2026
16 of 19 checks passed
@jeremy-morren
jeremy-morren deleted the fix-tph-table-splitting-dependent-filter branch November 13, 2026 17:21
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 14, 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.

Querying a table-splitting dependent of a derived TPH type returns rows of other types

3 participants