Skip to content

[release/11.0] Validate unsupported SQL Server JSON index options - #39090

Merged
AndriySvyryd merged 4 commits into
release/11.0from
copilot/fix-sql-server-json-index-unique
Sep 26, 2026
Merged

AndriySvyryd merged 4 commits into
release/11.0from
copilot/fix-sql-server-json-index-unique

Conversation

Copilot AI commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #39065

Description
SQL Server JSON indexes cannot express several options supported by ordinary indexes. EF Core generated CREATE JSON INDEX while silently dropping options such as uniqueness and descending order, or emitted clauses that SQL Server does not support. This change validates JSON index configuration and reports an error identifying the index and unsupported option. It continues to allow supported options and harmless explicit defaults, including fill factor, non-clustered, no include properties, offline creation, and disabled tempdb sorting.

Customer impact
Applications could configure a JSON-member index as unique but receive a non-unique database index, allowing duplicate values despite the model constraint. Other unsupported options could produce SQL that fails when a migration is applied. There was no warning that the intended constraint had been discarded.

builder.HasIndex(e => e.Details.Slug)
    .IsUnique();

How found
User reported on EF Core 11.0.0-rc1 .

Regression
No, SQL Server JSON index support was introduced in EF Core 11.

Testing
Tests added.

Risk
Low. SQL generation is unchanged. The validation only rejects options that SQL Server JSON indexes cannot express.

Copilot AI changed the title [WIP] Fix issue with IsUnique() on JSON mapped index in SQL Server Validate unsupported SQL Server JSON index options Sep 24, 2026
Copilot AI requested a review from AndriySvyryd September 24, 2026 23:59
@AndriySvyryd
AndriySvyryd requested a balanced review from Copilot September 25, 2026 00:21

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.

Copilot review overview

🟡 Changes recommended

Validation incorrectly rejects harmless explicit defaults such as nonclustered indexes and empty include lists.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds SQL Server model validation to prevent unsupported JSON index options from being silently ignored.

Changes:

  • Validates JSON index options during model finalization.
  • Adds provider-specific diagnostics.
  • Adds supported and unsupported option tests.
File Description
SqlServerModelValidator.cs Validates JSON index options.
SqlServerStrings.resx Adds validation error text.
SqlServerStrings.Designer.cs Exposes the generated error resource.
SqlServerModelValidatorTest.cs Tests option validation.
Files not reviewed (1)
  • src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs: Generated file

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/EFCore.SqlServer/Infrastructure/Internal/SqlServerModelValidator.cs Outdated
@AndriySvyryd
AndriySvyryd changed the base branch from main to release/11.0 September 25, 2026 00:49
@AndriySvyryd
AndriySvyryd force-pushed the copilot/fix-sql-server-json-index-unique branch from ff9645f to a563b93 Compare September 25, 2026 00:50
Copilot AI and others added 4 commits September 24, 2026 17:58
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

Copilot review overview

🟢 Approval recommended

The focused validation matches SQL Server JSON-index constraints and has comprehensive unit coverage.

Review effort: Balanced
Findings: None

Resolved since last review (1)
Files not reviewed (1)
  • src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs: Generated file

@AndriySvyryd AndriySvyryd changed the title Validate unsupported SQL Server JSON index options [release/11.0] Validate unsupported SQL Server JSON index options Sep 25, 2026
@AndriySvyryd
AndriySvyryd marked this pull request as ready for review September 25, 2026 01:30
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner September 25, 2026 01:30
@AndriySvyryd
AndriySvyryd requested a review from artl93 September 25, 2026 16:48

@artl93 artl93 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. New area. Customer reported.

@AndriySvyryd
AndriySvyryd merged commit 3142eb0 into release/11.0 Sep 26, 2026
26 checks passed
@AndriySvyryd
AndriySvyryd deleted the copilot/fix-sql-server-json-index-unique branch September 26, 2026 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET 11 RC1 - SQL Server: IsUnique() on an index over a JSON-mapped member is silently dropped

5 participants