Repository navigation
Don't add an IS NOT NULL filter to unique indexes on required TPT and TPC columns on SQL Server - #39161
Merged
AndriySvyryd merged 2 commits intoOct 8, 2026
Conversation
… TPC columns on SQL Server SqlServerIndexConvention computed the filter while the hierarchy still looked like TPH, so derived properties were treated as nullable. Re-evaluate the filters when the discriminator is removed, which is when the hierarchy is finalized as TPT or TPC. Fixes dotnet#32689
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Mixed-nullability composite indexes still retain redundant predicates for required columns.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Addresses #32689 by updating EF Core’s SQL Server index convention to remove redundant filters from required TPT/TPC columns.
Changes:
- Re-evaluates index filters when the discriminator changes.
- Adds regression tests for inferred TPT and late-configured TPC.
- Updates the public API baseline.
| File | Description |
|---|---|
| test/EFCore.SqlServer.FunctionalTests/ModelBuilding/SqlServerModelBuilderTestBase.cs | Adds TPT/TPC regression coverage. |
| src/EFCore.SqlServer/Metadata/Conventions/SqlServerIndexConvention.cs | Handles discriminator changes to refresh filters. |
| src/EFCore.SqlServer/EFCore.SqlServer.baseline.json | Records the new interface and callback. |
A composite unique index over a required and a nullable column got a filter for both columns while the hierarchy still looked like TPH, and the filter was kept because one already existed. Regenerate it so only the nullable columns remain; explicitly configured filters are still left alone.
AndriySvyryd
approved these changes
Oct 8, 2026
AndriySvyryd
left a comment
Member
There was a problem hiding this comment.
Thanks for your contribution!
Contributor
API review baseline changes for
|
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 #32689
SqlServerIndexConventionadds a[Column] IS NOT NULLfilter to unique indexes over nullable columns. For derived types it ran while the hierarchy still had a discriminator, so the hierarchy looked like TPH and required derived properties were seen as nullable. The mapping strategy is only settled at finalization, when the discriminator is removed for TPT and TPC hierarchies, and nothing re-ran the filter after that, so TPT and TPC tables kept a redundant filter on non-nullable columns.The convention now also implements
IDiscriminatorPropertySetConventionand re-evaluates the filters of the indexes in that hierarchy when the discriminator changes. Filters configured explicitly are left alone, as before.Tests added in
SqlServerModelBuilderTestBasefor an inferred TPT hierarchy and for TPC configured after the index; both fail on main.Note: models that already have migrations will see the filter dropped from these indexes in their next migration.