Add support for SQL Server JSON indexes#38302
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends EF Core’s index/key infrastructure to understand complex-property paths (including JSON-mapped complex types and complex collections), and updates design-time/runtime code generation and scaffolding to carry the additional metadata needed for those paths.
Changes:
- Generalize index metadata from scalar-only properties to
IPropertyBase, addingIReadOnlyIndex.CollectionIndicesto represent complex-collection traversal and fixed indexers (e.g.Posts[0]vsPosts.Select(...)). - Update relational/SQL Server behaviors (validation, naming, annotation generation, scaffolding) to support dotted property paths and JSON-path index metadata.
- Add/adjust tests and compiled-model baselines covering complex-type index/key scenarios, JSON-path indexes, and provider-specific behavior (SQL Server/Cosmos).
Reviewed changes
Copilot reviewed 124 out of 127 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/EFCore.Tests/Metadata/Internal/PropertyListComparerTest.cs | New unit tests for property list comparison across complex-type paths. |
| test/EFCore.Tests/Metadata/Internal/InternalEntityTypeBuilderTest.cs | Adjusts index lookups and adds coverage for resolving stale complex properties. |
| test/EFCore.Tests/Metadata/Internal/EntityTypeTest.cs | Updates index removal calls for the new property-base index APIs. |
| test/EFCore.Tests/Metadata/Conventions/ConventionDispatcherTest.cs | Updates convention test to remove indexes using property-base lists. |
| test/EFCore.Tests/Infrastructure/ModelValidatorTest.cs | Adds validation tests for keys/indexes involving complex properties and complex collections. |
| test/EFCore.Tests/Extensions/ExpressionExtensionsTest.cs | Adds tests for parsing complex member-access chains (selects/indexers) for index expressions. |
| test/EFCore.Tests/Diagnostics/CoreEventIdTest.cs | Updates a test stub to include the newly required IsInModel override. |
| test/EFCore.SqlServer.Tests/Infrastructure/SqlServerModelValidatorTest.cs | Adds SQL Server tests for include-property dotted paths and vector index + complex type cases. |
| test/EFCore.SqlServer.FunctionalTests/Scaffolding/SqlServerDatabaseModelFactoryTest.cs | Adds scaffolding tests for SQL Server JSON index paths (including mixed index types). |
| test/EFCore.SqlServer.FunctionalTests/Scaffolding/CompiledModelSqlServerTest.cs | Adds compiled-model test for JSON-path indexes through complex collections and adjusts complex type model. |
| test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Json_path_indexes_through_complex_collections/JsonPathIndexPostUnsafeAccessors.cs | New compiled-model baseline accessor file for JSON-path index scenario. |
| test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Json_path_indexes_through_complex_collections/JsonPathIndexEntityUnsafeAccessors.cs | New compiled-model baseline accessor file for JSON-path index scenario. |
| test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Json_path_indexes_through_complex_collections/JsonPathIndexAddressUnsafeAccessors.cs | New compiled-model baseline accessor file for JSON-path index scenario. |
| test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Json_path_indexes_through_complex_collections/DbContextModel.cs | New compiled-model baseline runtime model for JSON-path index scenario. |
| test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/Json_path_indexes_through_complex_collections/DbContextAssemblyAttributes.cs | New compiled-model baseline assembly attributes for JSON-path index scenario. |
| test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/ComplexTypes/PrincipalDerivedUnsafeAccessors.cs | Updates compiled-model baselines for complex-type model changes. |
| test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/ComplexTypes/PrincipalBaseEntityType.cs | Updates compiled-model baseline to include a named index involving a complex-type leaf. |
| test/EFCore.SqlServer.FunctionalTests/Scaffolding/Baselines/ComplexTypes/DependentBaseUnsafeAccessors.cs | New compiled-model baseline accessor for dependent type changes. |
| test/EFCore.Specification.Tests/TestUtilities/ModelAsserter.cs | Ensures model comparisons include CollectionIndices and clones indexes with collection indices. |
| test/EFCore.Specification.Tests/Scaffolding/CompiledModelTestBase.cs | Updates base compiled-model tests/models for indexes + complex property changes and provider capability gating. |
| test/EFCore.Specification.Tests/Query/AdHocComplexTypeQueryTestBase.cs | Adds end-to-end query/update/delete tests for indexes and alternate keys on complex-property leaves. |
| test/EFCore.Specification.Tests/ModelBuilding/ModelBuilderTest.NonGeneric.cs | Updates non-generic model builder tests to use member-access chains (dotted names). |
| test/EFCore.Specification.Tests/ModelBuilding/ModelBuilderTest.Inheritance.cs | Updates index property comparisons for the new index property-base types. |
| test/EFCore.Relational.Tests/Metadata/RelationalModelTest.cs | Adds relational model mapping tests for AK/index on complex properties and path-based index lookup. |
| test/EFCore.Relational.Specification.Tests/Scaffolding/CompiledModelRelationalTestBase.cs | Extends relational compiled-model complex type scenario with JSON-mapped complex property index. |
| test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/ComplexTypes/PrincipalDerivedUnsafeAccessors.cs | Updates InMemory compiled-model baselines for complex-type model changes. |
| test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/ComplexTypes/PrincipalBaseEntityType.cs | Updates InMemory baseline to include named index involving complex-type leaf. |
| test/EFCore.InMemory.FunctionalTests/Scaffolding/Baselines/ComplexTypes/DependentBaseUnsafeAccessors.cs | New InMemory baseline accessor for dependent type changes. |
| test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTestBase.cs | Adds a “partial snapshot” assertion mode for generator tests. |
| test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.cs | Adds new relational annotation names for generator coverage (JSON index annotations). |
| test/EFCore.Cosmos.Tests/Infrastructure/CosmosModelValidatorTest.cs | Adds Cosmos test for vector index on a complex-type leaf property. |
| test/EFCore.Cosmos.FunctionalTests/Scaffolding/CompiledModelCosmosTest.cs | Updates Cosmos compiled-model scaffolding behavior flags for complex types/index support differences. |
| test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/ComplexTypes/PrincipalDerivedUnsafeAccessors.cs | Updates Cosmos baselines for complex-type model changes. |
| test/EFCore.Cosmos.FunctionalTests/Scaffolding/Baselines/ComplexTypes/DependentBaseUnsafeAccessors.cs | New Cosmos baseline accessor for dependent type changes. |
| test/EFCore.Cosmos.FunctionalTests/Query/AdHocComplexTypeQueryCosmosTest.cs | Overrides new specification tests to assert Cosmos provider error behavior around indexes. |
| test/EFCore.Cosmos.FunctionalTests/ModelBuilding/CosmosModelBuilderGenericTest.cs | Adds Cosmos overrides for index-on-complex-property model-building tests (expected failures). |
| src/EFCore/Properties/CoreStrings.resx | Adds new core validation/error strings related to complex properties, collection indices, and JSON paths. |
| src/EFCore/Properties/CoreStrings.Designer.cs | Strongly-typed accessors for newly added core strings. |
| src/EFCore/Metadata/RuntimePropertyBase.cs | Moves runtime index list storage up to RuntimePropertyBase. |
| src/EFCore/Metadata/RuntimeProperty.cs | Removes duplicated runtime index list storage from RuntimeProperty. |
| src/EFCore/Metadata/RuntimeKey.cs | Fixes key declaring entity type resolution for properties declared on complex types. |
| src/EFCore/Metadata/RuntimeIndex.cs | Generalizes runtime index properties to RuntimePropertyBase and adds runtime CollectionIndices. |
| src/EFCore/Metadata/RuntimeEntityType.cs | Updates runtime index storage/lookup to use property-base lists and pass collection indices. |
| src/EFCore/Metadata/IReadOnlyIndex.cs | Changes index properties to IReadOnlyPropertyBase and adds CollectionIndices. |
| src/EFCore/Metadata/IReadOnlyEntityType.cs | Updates index lookup signatures to accept IReadOnlyPropertyBase. |
| src/EFCore/Metadata/Internal/UnnamedIndexKey.cs | New internal key type to represent unnamed-index identity including collection indices. |
| src/EFCore/Metadata/Internal/TypeBase.cs | Introduces complex-property ordering via a comparer and exposes ContainingEntityType. |
| src/EFCore/Metadata/Internal/SkipNavigation.cs | Aligns IsInModel override with new abstract base member. |
| src/EFCore/Metadata/Internal/ServiceProperty.cs | Aligns IsInModel override with new abstract base member. |
| src/EFCore/Metadata/Internal/PropertyNameComparer.cs | Ensures primary-key ordering is applied per declaring type (complex type vs entity). |
| src/EFCore/Metadata/Internal/PropertyListComparer.cs | Distinguishes properties by declaring type to avoid collisions across complex types. |
| src/EFCore/Metadata/Internal/PropertyBase.cs | Adds IsInModel and index containment support to PropertyBase (not only scalar property). |
| src/EFCore/Metadata/Internal/Property.cs | Adjusts IsInModel override and removes duplicated index containment plumbing. |
| src/EFCore/Metadata/Internal/Navigation.cs | Aligns IsInModel override with new abstract base member. |
| src/EFCore/Metadata/Internal/Key.cs | Fixes key declaring entity type resolution for complex-type-declared properties. |
| src/EFCore/Metadata/Internal/InternalTypeBaseBuilder.cs | Adds/updates complex-chain resolution for property creation and “actual properties” resolution. |
| src/EFCore/Metadata/Internal/InternalIndexBuilder.cs | Updates reattach logic to rebuild complex-property chains and preserve collection indices. |
| src/EFCore/Metadata/Internal/ComplexType.cs | Simplifies containing-entity resolution via ContainingEntityType. |
| src/EFCore/Metadata/Internal/ComplexPropertyNameComparer.cs | New comparer to order complex properties relative to PK usage. |
| src/EFCore/Metadata/Internal/ComplexProperty.cs | Aligns IsInModel override with new abstract base member. |
| src/EFCore/Metadata/IMutableIndex.cs | Updates mutable index properties to IMutablePropertyBase and exposes CollectionIndices. |
| src/EFCore/Metadata/IMutableEntityType.cs | Updates index APIs to accept property bases and adds overloads for collection indices (default throws). |
| src/EFCore/Metadata/IIndex.cs | Updates index properties to IPropertyBase. |
| src/EFCore/Metadata/IEntityType.cs | Updates index lookup signatures to accept IReadOnlyPropertyBase. |
| src/EFCore/Metadata/IConventionIndex.cs | Updates convention index properties to IConventionPropertyBase. |
| src/EFCore/Metadata/IConventionEntityType.cs | Updates convention entity-type index APIs to use property bases. |
| src/EFCore/Metadata/Conventions/RuntimeModelConvention.cs | Updates runtime model creation to resolve runtime properties along complex-type chains. |
| src/EFCore/Metadata/Conventions/KeyComplexPropertyConvention.cs | New convention to mark complex-property chains as required when referenced by keys. |
| src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilder.cs | Registers the new key/complex-property convention. |
| src/EFCore/Metadata/Conventions/ForeignKeyIndexConvention.cs | Avoids treating JSON-path indexes (with collection indices) as covering/covered by FK indexes. |
| src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs | Updates key/index lambdas to use member-access chains and complex-member matching with collection indices. |
| src/EFCore/Infrastructure/ModelValidator.cs | Adds key/index validation for complex-property chains and forbids indexes on complex properties (core). |
| src/EFCore/Design/ICSharpHelper.cs | Adds lambda generation support for IPropertyBase via dotted paths from containing entity. |
| src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs | Adds JSON index path discovery from SQL Server metadata and annotates scaffolded indexes. |
| src/EFCore.SqlServer/Metadata/Internal/SqlServerIndexExtensions.cs | Updates include-property resolution to support dotted paths to complex properties. |
| src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationProvider.cs | Preserves base table-index annotations and resolves include columns using path-based property lookup. |
| src/EFCore.SqlServer/Metadata/Conventions/SqlServerIndexConvention.cs | Avoids generating unique-index filters when index contains complex properties. |
| src/EFCore.SqlServer/Infrastructure/Internal/SqlServerModelValidator.cs | Validates include paths via property-path lookup and adapts FTS/vector validation for property-base lists. |
| src/EFCore.SqlServer/Extensions/SqlServerIndexBuilderExtensions.cs | Updates include-property lambda parsing to generate dotted paths. |
| src/EFCore.Relational/Update/ModificationCommand.cs | Updates JSON ordinal/index handling to support nullable indices (unspecified array elements). |
| src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs | Adjusts uniqueness detection to ignore non-scalar index properties. |
| src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.CreateSelect.cs | Binds PK properties declared on complex types by traversing complex projections. |
| src/EFCore.Relational/Properties/RelationalStrings.resx | Adds relational error strings for JSON/complex-property index/key constraints. |
| src/EFCore.Relational/Properties/RelationalStrings.Designer.cs | Strongly-typed accessors for newly added relational strings. |
| src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs | Considers JSON index annotation equivalence when diffing table indexes. |
| src/EFCore.Relational/Metadata/RelationalJsonIndex.cs | New model type describing JSON index elements + collection indices for diffing/annotations. |
| src/EFCore.Relational/Metadata/RelationalAnnotationProvider.cs | Emits design-time JSON index annotation for table indexes mapped to JSON paths. |
| src/EFCore.Relational/Metadata/RelationalAnnotationNames.cs | Adds relational annotation names for JSON index + scaffolded JSON index paths. |
| src/EFCore.Relational/Metadata/Internal/RelationalModel.cs | Maps indexes over JSON-contained properties to container columns and supports path-based key/index lookup. |
| src/EFCore.Relational/Metadata/Internal/RelationalIndexExtensions.cs | Updates index compatibility logic to use computed column names (including JSON container columns). |
| src/EFCore.Relational/Metadata/Internal/JsonColumnBase.cs | Uses store-type-aware mapping lookup for JSON placeholder mappings. |
| src/EFCore.Relational/Metadata/Internal/JsonColumn.cs | Uses store-type-aware mapping lookup for JSON placeholder mappings. |
| src/EFCore.Relational/Metadata/IColumnBase.cs | Fixes property-mapping selection for properties declared on complex types in inheritance scenarios. |
| src/EFCore.Relational/Infrastructure/StructuredJsonPath.cs | Extends structured JSON paths to support nullable indices and wildcard/omitted rendering. |
| src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs | Updates “should be mapped” logic for complex-type-declared properties across derived types/tables. |
| src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs | Adjusts default index naming to disambiguate JSON-path indexes sharing a container column. |
| src/EFCore.Relational/Extensions/RelationalComplexPropertyExtensions.cs | Adds helper to enumerate mapped store objects for JSON-mapped complex properties. |
| src/EFCore.Relational/EFCore.Relational.baseline.json | Updates API baseline to include new public surface area (JSON index types/annotations, signature changes). |
| src/EFCore.Relational/Design/Internal/RelationalCSharpRuntimeAnnotationCodeGenerator.cs | Updates relational runtime annotation generation to use dotted property paths and suppress JSON-index annotations where appropriate. |
| src/EFCore.Design/Scaffolding/Internal/CSharpRuntimeModelCodeGenerator.cs | Updates runtime model code generation to find complex-type properties and emit collection indices literals. |
| src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs | Regenerates T4 output metadata/version and adjusts base generator member visibility. |
| src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs | Regenerates T4 output metadata/version for DbContext generator. |
| src/EFCore.Design/Properties/DesignStrings.resx | Reorders/adds resource strings (no semantic content change implied beyond ordering). |
| src/EFCore.Design/Properties/DesignStrings.Designer.cs | Regenerates strongly-typed designer for reordered/added resources. |
| src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs | Updates snapshot generation to emit complex-property/indexer paths for index properties. |
| src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs | Ensures vector/full-text metadata is discovered inside complex properties recursively. |
| src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs | Builds JSON property paths for complex-type-declared properties (including collections) for Cosmos indexes. |
| src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs | Hardens vector/full-text validation against non-scalar index property entries. |
| .agents/skills/run-apichief/SKILL.md | Updates ApiChief skill guidance for baseline-only updates. |
Files not reviewed (3)
- src/EFCore.Design/Properties/DesignStrings.Designer.cs: Language not supported
- src/EFCore.Relational/Properties/RelationalStrings.Designer.cs: Language not supported
- src/EFCore/Properties/CoreStrings.Designer.cs: Language not supported
866e58a to
1906470
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 56 out of 58 changed files in this pull request and generated 4 comments.
Files not reviewed (2)
- src/EFCore.Relational/Properties/RelationalStrings.Designer.cs: Language not supported
- src/EFCore/Properties/CoreStrings.Designer.cs: Language not supported
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 54 out of 56 changed files in this pull request and generated 9 comments.
Files not reviewed (2)
- src/EFCore.Relational/Properties/RelationalStrings.Designer.cs: Language not supported
- src/EFCore/Properties/CoreStrings.Designer.cs: Language not supported
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 57 out of 60 changed files in this pull request and generated 3 comments.
Files not reviewed (3)
- src/EFCore.Relational/Properties/RelationalStrings.Designer.cs: Language not supported
- src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs: Language not supported
- src/EFCore/Properties/CoreStrings.Designer.cs: Language not supported
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 57 out of 60 changed files in this pull request and generated 3 comments.
Files not reviewed (3)
- src/EFCore.Relational/Properties/RelationalStrings.Designer.cs: Language not supported
- src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs: Language not supported
- src/EFCore/Properties/CoreStrings.Designer.cs: Language not supported
Add support for chaining into complex collections in indexes
Fixes #11336
Fixes #29623