Repository navigation
Filter required table-splitting dependents of a derived TPH type by its discriminator - #39528
Merged
AndriySvyryd merged 1 commit intoNov 13, 2026
Conversation
Contributor
There was a problem hiding this comment.
🟡 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
force-pushed
the
fix-tph-table-splitting-dependent-filter
branch
from
November 4, 2026 22:12
10af778 to
a97b0c7
Compare
AndriySvyryd
approved these changes
Nov 13, 2026
AndriySvyryd
left a comment
Member
There was a problem hiding this comment.
Thanks for your contribution!
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.

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, includingDogrows. It's now filtered by the principal's discriminator, like 6.0 did, but without the join.Optional dependents keep their existing
IS NOT NULLexistence checks.Tests:
TableSplittingTestBase.Can_query_required_dependent_of_derived_type, with SQL Server and SQLite baselines.