Skip to content

Add support for SQL Server JSON indexes - #38302

Merged
AndriySvyryd merged 1 commit into
mainfrom
Issue11336
Jun 3, 2026
Merged

AndriySvyryd merged 1 commit into
mainfrom
Issue11336

Conversation

@AndriySvyryd

@AndriySvyryd AndriySvyryd commented May 20, 2026 •

Copy link
Copy Markdown
Member

Add support for chaining into complex collections in indexes

Fixes #11336
Fixes #35287
Fixes #29623

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.

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, adding IReadOnlyIndex.CollectionIndices to represent complex-collection traversal and fixed indexers (e.g. Posts[0] vs Posts.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

@AndriySvyryd AndriySvyryd changed the title Issue11336 Add support for JSON indexes May 20, 2026
@AndriySvyryd
AndriySvyryd force-pushed the Issue11336 branch 2 times, most recently from 866e58a to 1906470 Compare May 20, 2026 19:37
@AndriySvyryd
AndriySvyryd marked this pull request as ready for review May 20, 2026 19:37
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner May 20, 2026 19:37
Copilot AI review requested due to automatic review settings May 20, 2026 19:37

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.

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

@AndriySvyryd AndriySvyryd changed the title Add support for JSON indexes Add support for SQL Server JSON indexes May 20, 2026
Copilot AI review requested due to automatic review settings May 21, 2026 01:08

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.

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

Comment thread src/EFCore/Properties/CoreStrings.resx Resolved
Copilot AI review requested due to automatic review settings May 22, 2026 22:43

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.

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

Copilot AI review requested due to automatic review settings May 23, 2026 01:15

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.

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

Comment thread src/EFCore/Properties/CoreStrings.resx Resolved
Copilot AI review requested due to automatic review settings May 25, 2026 07:19
Copilot AI review requested due to automatic review settings May 27, 2026 06:59

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.

Pull request overview

Copilot reviewed 57 out of 60 changed files in this pull request and generated 1 comment.

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

Copilot AI review requested due to automatic review settings May 28, 2026 03:08

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.

Pull request overview

Copilot reviewed 59 out of 62 changed files in this pull request and generated 1 comment.

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

@AndriySvyryd
AndriySvyryd enabled auto-merge (squash) June 3, 2026 18:27
Copilot AI review requested due to automatic review settings June 3, 2026 21:04
Add support for chaining into complex collections in indexes

Fixes #11336
Fixes #29623
Fixes #35287

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.

Pull request overview

Copilot reviewed 65 out of 70 changed files in this pull request and generated 2 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

@AndriySvyryd
AndriySvyryd merged commit c72e242 into main Jun 3, 2026
14 checks passed
@AndriySvyryd
AndriySvyryd deleted the Issue11336 branch June 3, 2026 21:28
@github-actions github-actions Bot added the api-review This PR or issue is introducing public API changes that need to be reviewed label Jun 3, 2026
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

API review baseline changes for src/EFCore.Design/EFCore.Design.baseline.json

Show diff

The diff below was generated by ApiChief between the base and the PR.

  class Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator : Microsoft.EntityFrameworkCore.Migrations.Design.ICSharpSnapshotGenerator
- virtual void GenerateComplexProperties(string typeBuilderName, IEnumerable<IComplexProperty> properties, IndentedStringBuilder stringBuilder);
+ virtual void GenerateComplexProperties(string typeBuilderName, IEnumerable<IComplexProperty> properties, CSharpSnapshotGeneratorParameters parameters);
- virtual void GenerateComplexProperty(string builderName, IComplexProperty complexProperty, IndentedStringBuilder stringBuilder);
+ virtual void GenerateComplexProperty(string builderName, IComplexProperty complexProperty, CSharpSnapshotGeneratorParameters parameters);
- virtual void GenerateForeignKeys(string entityTypeBuilderName, IEnumerable<IForeignKey> foreignKeys, IndentedStringBuilder stringBuilder);
+ virtual void GenerateForeignKeys(string entityTypeBuilderName, IEnumerable<IForeignKey> foreignKeys, CSharpSnapshotGeneratorParameters parameters);
- virtual void GenerateIndex(string entityTypeBuilderName, IIndex index, IndentedStringBuilder stringBuilder);
+ virtual void GenerateIndex(string entityTypeBuilderName, IIndex index, CSharpSnapshotGeneratorParameters parameters);
- virtual void GenerateIndexes(string entityTypeBuilderName, IEnumerable<IIndex> indexes, IndentedStringBuilder stringBuilder);
+ virtual void GenerateIndexes(string entityTypeBuilderName, IEnumerable<IIndex> indexes, CSharpSnapshotGeneratorParameters parameters);
- virtual void GenerateKey(string entityTypeBuilderName, IKey key, IndentedStringBuilder stringBuilder, bool primary = false);
+ virtual void GenerateKey(string entityTypeBuilderName, IKey key, CSharpSnapshotGeneratorParameters parameters, bool primary = false);
- virtual void GenerateKeys(string entityTypeBuilderName, IEnumerable<IKey> keys, IKey? primaryKey, IndentedStringBuilder stringBuilder);
+ virtual void GenerateKeys(string entityTypeBuilderName, IEnumerable<IKey> keys, IKey? primaryKey, CSharpSnapshotGeneratorParameters parameters);
- virtual void GenerateNavigations(string entityTypeBuilderName, IEnumerable<INavigation> navigations, IndentedStringBuilder stringBuilder);
+ virtual void GenerateNavigations(string entityTypeBuilderName, IEnumerable<INavigation> navigations, CSharpSnapshotGeneratorParameters parameters);
- virtual void GenerateProperties(string entityTypeBuilderName, IEnumerable<IProperty> properties, IndentedStringBuilder stringBuilder);
+ virtual void GenerateProperties(string entityTypeBuilderName, IEnumerable<IProperty> properties, CSharpSnapshotGeneratorParameters parameters);
- virtual void GenerateProperty(string entityTypeBuilderName, IProperty property, IndentedStringBuilder stringBuilder);
+ virtual void GenerateProperty(string entityTypeBuilderName, IProperty property, CSharpSnapshotGeneratorParameters parameters);
- virtual void GenerateRelationships(string entityTypeBuilderName, IEntityType entityType, IndentedStringBuilder stringBuilder);
+ virtual void GenerateRelationships(string entityTypeBuilderName, IEntityType entityType, CSharpSnapshotGeneratorParameters parameters);
- virtual void GenerateIndexAnnotations(string indexBuilderName, IIndex index, IndentedStringBuilder stringBuilder);
- virtual void GenerateKeyAnnotations(string keyBuilderName, IKey key, IndentedStringBuilder stringBuilder);
- virtual void GeneratePropertyAnnotations(string propertyBuilderName, IProperty property, IndentedStringBuilder stringBuilder);
+ sealed record Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGeneratorParameters
+ ICollection<string> Scope { get; init; }
+ IndentedStringBuilder StringBuilder { get; init; }
+ static bool operator !=(CSharpSnapshotGeneratorParameters? left, CSharpSnapshotGeneratorParameters? right);
+ CSharpSnapshotGeneratorParameters <Clone>$();
+ static bool operator ==(CSharpSnapshotGeneratorParameters? left, CSharpSnapshotGeneratorParameters? right);
+ bool Equals(CSharpSnapshotGeneratorParameters? other);
+ override bool Equals(object? obj);
+ override int GetHashCode();
+ override string ToString();

API review baseline changes for src/EFCore.Relational/EFCore.Relational.baseline.json

Show diff

The diff below was generated by ApiChief between the base and the PR.

  static class Microsoft.EntityFrameworkCore.Diagnostics.RelationalStrings
+ static string JsonPathIndexElementsCollectionIndicesMismatch(object? elementCount, object? collectionIndicesCount);
+ static string JsonPathIndexPropertiesInDifferentJsonColumns(object? indexProperties, object? entityType, object? firstColumn, object? secondColumn);
+ static string JsonPathIndexPropertyMissingJsonColumn(object? indexProperties, object? entityType, object? property);
  class Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator : Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator
+ override void ValidateIndexProperty(IIndex index, IPropertyBase property, IDiagnosticsLogger<Validation> logger);
  class Microsoft.EntityFrameworkCore.Infrastructure.StructuredJsonPath
- virtual StringBuilder AppendTo(StringBuilder builder);
+ virtual StringBuilder AppendTo(StringBuilder builder, bool useAsteriskForNullIndex = true);
- virtual int[] Indices { get; }
+ virtual IReadOnlyList<int?>? Indices { get; }
- StructuredJsonPath(IReadOnlyList<StructuredJsonPathSegment> segments, int[] indices);
+ StructuredJsonPath(IReadOnlyList<StructuredJsonPathSegment> segments, IReadOnlyList<int?>? indices);
+ virtual string ToString(bool useAsteriskForNullIndex = true);
  static class Microsoft.EntityFrameworkCore.Metadata.RelationalAnnotationNames
+ const string JsonIndex
+ const string JsonIndexPaths
  class Microsoft.EntityFrameworkCore.Metadata.RelationalAnnotationProvider : Microsoft.EntityFrameworkCore.Metadata.IRelationalAnnotationProvider
+ static IRelationalJsonElement FindJsonElement(IPropertyBase property, ITable table);
+ virtual bool IsJsonIndex(IIndex index);
+ virtual RelationalJsonIndex? TryBuildJsonIndex(ITableIndex index);
+ sealed class Microsoft.EntityFrameworkCore.Metadata.RelationalJsonIndex : System.IEquatable<Microsoft.EntityFrameworkCore.Metadata.RelationalJsonIndex>
+ IReadOnlyList<IReadOnlyList<int?>?>? CollectionIndices { get; }
+ IReadOnlyList<IRelationalJsonElement> Elements { get; }
+ bool Equals(RelationalJsonIndex? other);
+ override bool Equals(object? obj);
+ override int GetHashCode();
+ RelationalJsonIndex(IReadOnlyList<IRelationalJsonElement> elements, IReadOnlyList<IReadOnlyList<int?>?>? collectionIndices);

API review baseline changes for src/EFCore/EFCore.baseline.json

Show diff

The diff below was generated by ApiChief between the base and the PR.

  static class Microsoft.EntityFrameworkCore.Diagnostics.CoreStrings
+ static string ConflictingNamedIndex(object? indexName, object? entityType, object? propertyList);
+ static string InvalidCollectionIndicesEntryLength(object? property, object? indexProperties, object? actualCount, object? expectedCount);
+ static string InvalidNumberOfIndexCollectionIndices(object? indexProperties, object? numValues, object? numProperties);
  class Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator : Microsoft.EntityFrameworkCore.Infrastructure.IModelValidator
+ virtual void ValidateIndexProperty(IIndex index, IPropertyBase property, IDiagnosticsLogger<Validation> logger);
  class Microsoft.EntityFrameworkCore.Metadata.Conventions.ForeignKeyIndexConvention :
      Microsoft.EntityFrameworkCore.Metadata.Conventions.IForeignKeyAddedConvention, Microsoft.EntityFrameworkCore.Metadata.Conventions.IConvention,
      Microsoft.EntityFrameworkCore.Metadata.Conventions.IForeignKeyRemovedConvention,
      Microsoft.EntityFrameworkCore.Metadata.Conventions.IForeignKeyPropertiesChangedConvention,
      Microsoft.EntityFrameworkCore.Metadata.Conventions.IForeignKeyUniquenessChangedConvention,
      Microsoft.EntityFrameworkCore.Metadata.Conventions.IKeyAddedConvention, Microsoft.EntityFrameworkCore.Metadata.Conventions.IKeyRemovedConvention,
      Microsoft.EntityFrameworkCore.Metadata.Conventions.IEntityTypeBaseTypeChangedConvention,
      Microsoft.EntityFrameworkCore.Metadata.Conventions.IIndexAddedConvention, Microsoft.EntityFrameworkCore.Metadata.Conventions.IIndexRemovedConvention,
      Microsoft.EntityFrameworkCore.Metadata.Conventions.IIndexUniquenessChangedConvention,
      Microsoft.EntityFrameworkCore.Metadata.Conventions.IModelFinalizingConvention
+ static bool IsNonComplexCollectionIndex(IConventionIndex index);
  interface Microsoft.EntityFrameworkCore.Metadata.IMutableEntityType : Microsoft.EntityFrameworkCore.Metadata.IReadOnlyEntityType,
      Microsoft.EntityFrameworkCore.Metadata.IReadOnlyTypeBase, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable,
      Microsoft.EntityFrameworkCore.Metadata.IMutableTypeBase, Microsoft.EntityFrameworkCore.Metadata.IMutableAnnotatable
+ IMutableIndex AddIndex(IReadOnlyList<IMutablePropertyBase> properties, IReadOnlyList<IReadOnlyList<int?>?>? collectionIndices);
+ IMutableIndex AddIndex(IReadOnlyList<IMutablePropertyBase> properties, IReadOnlyList<IReadOnlyList<int?>?>? collectionIndices, string name);
  interface Microsoft.EntityFrameworkCore.Metadata.IMutableIndex : Microsoft.EntityFrameworkCore.Metadata.IReadOnlyIndex,
      Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable, Microsoft.EntityFrameworkCore.Metadata.IMutableAnnotatable
+ IReadOnlyList<IReadOnlyList<int?>?>? CollectionIndices { get; }
  interface Microsoft.EntityFrameworkCore.Metadata.IReadOnlyIndex : Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable
+ IReadOnlyList<IReadOnlyList<int?>?>? CollectionIndices { get; }
  class Microsoft.EntityFrameworkCore.Metadata.RuntimeEntityType : Microsoft.EntityFrameworkCore.Metadata.RuntimeTypeBase,
      Microsoft.EntityFrameworkCore.Metadata.Internal.IRuntimeEntityType, Microsoft.EntityFrameworkCore.Metadata.IEntityType,
      Microsoft.EntityFrameworkCore.Metadata.IReadOnlyEntityType, Microsoft.EntityFrameworkCore.Metadata.IReadOnlyTypeBase,
      Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable, Microsoft.EntityFrameworkCore.Metadata.ITypeBase,
      Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Metadata.Internal.IRuntimeTypeBase
- virtual RuntimeIndex AddIndex(IReadOnlyList<RuntimePropertyBase> properties, string? name = null, bool unique = false);
+ virtual RuntimeIndex AddIndex(IReadOnlyList<RuntimePropertyBase> properties, string? name = null, bool unique = false,
+     IReadOnlyList<IReadOnlyList<int?>?>? collectionIndices = null);

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 5, 2026
m-x-shokhzod added a commit to m-x-shokhzod/efcore that referenced this pull request Jun 9, 2026
Rebasing onto main surfaced two interactions:

- SQL Server JSON indexes (dotnet#38302) are emitted as a DropIndex + CreateIndex
  pair, and CREATE JSON INDEX supports WITH (DROP_EXISTING = ON), so the
  existing rewrite collapses them like any other index. Update the
  Change_json_index_path[_index] tests to expect the single-statement form.
- xUnit v3 makes the parameterless ConditionalFact obsolete; use [Fact] for the
  unconditional DROP_EXISTING tests, matching the base MigrationsTestBase.
@AndriySvyryd AndriySvyryd removed the api-review This PR or issue is introducing public API changes that need to be reviewed label Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve the exception when adding an index over a JSON column SQL Server: Support JSON indexes Allow defining indexes on complex collections

4 participants