Add validation for Index included properties inside JSON-mapped types#38404
Open
AndriySvyryd wants to merge 4 commits into
Open
Add validation for Index included properties inside JSON-mapped types#38404AndriySvyryd wants to merge 4 commits into
AndriySvyryd wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds SQL Server-specific model validation to prevent configuring index included properties that traverse complex collections (JSON-mapped), and expands test coverage to lock in the expected behavior and SQL generation for complex-property includes.
Changes:
- Add
SqlServerModelValidatorvalidation that throws when an index include path traverses a complex collection. - Add a new provider error message resource (
IncludePropertyTraversesComplexCollection). - Add/extend tests: model-validation coverage for the new error, and a migrations functional test verifying
INCLUDEcolumn name generation for a complex property path.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/EFCore.SqlServer.Tests/Infrastructure/SqlServerModelValidatorTest.cs | Adds a regression test asserting an exception when an index include path traverses a complex collection. |
| test/EFCore.SqlServer.FunctionalTests/Migrations/MigrationsSqlServerTest.cs | Adds a functional test ensuring complex-property include paths translate to the expected included column name in generated SQL. |
| src/EFCore.SqlServer/Properties/SqlServerStrings.resx | Adds a new localized error message for invalid include paths over complex collections. |
| src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs | Adds the strongly-typed accessor for the new resource string. |
| src/EFCore.SqlServer/Infrastructure/Internal/SqlServerModelValidator.cs | Implements the new include-property validation logic and helper for detecting complex-collection traversal. |
Files not reviewed (1)
- src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs: Language not supported
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…SON-mapped type Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot
AI
changed the title
Add validation for Index included complex collection properties
Add validation for Index included properties inside JSON-mapped types
Jun 10, 2026
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.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.
Adds SQL Server-specific model validation to prevent configuring index
INCLUDEproperties that are nested inside a JSON-mapped type, and updates the annotation provider to correctly resolve JSON complex property paths to their container column names.Changes
SqlServerModelValidator: Replace the "traverses a complex collection" check with a broader check onpropertyBase.DeclaringType.IsMappedToJson(). This correctly rejects any include path whose target property lives inside a JSON-mapped type (collection or non-collection), while still allowing the JSON column itself to be included directly.SqlServerAnnotationProvider: Update include-column resolution to useFindPropertyBaseByPathand handle complex property paths by returning the JSON container column name viaComplexType.GetContainerColumnName().SqlServerStrings: ReplaceIncludePropertyTraversesComplexCollectionresource withIncludePropertyInJsonMappedType(3 parameters, nocomplexCollectionargument).