Skip to content

Conversation

@roji
Copy link
Member

@roji roji commented Jan 25, 2026

  • Does not include Contains over structural types, only scalars.
  • Does not support both nullable item and collections over nullable types because of limitations of JSON_CONTAINS() (which does not support searching NULL). For that case we retain the default OPENJSON translation.

Note: JSON_CONTAINS() is still in preview at the time of writing, but can offer some significant performance advantages (as it can take advantage of JSON indexes).

Closes #36656
Fixes #37561

Copilot AI review requested due to automatic review settings January 25, 2026 18:38
@roji roji requested a review from a team as a code owner January 25, 2026 18:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request implements JSON_CONTAINS() support for non-nullable primitive collections on SQL Server 2025+ (compatibility level 170+). The implementation translates Contains operations over non-nullable primitive collections to the more efficient JSON_CONTAINS function instead of the previous OPENJSON-based approach.

Changes:

  • Adds JSON_CONTAINS support detection in infrastructure (SqlServerSingletonOptions, TestEnvironment)
  • Implements TranslateContains override to use JSON_CONTAINS for non-nullable collections
  • Adds null-handling logic in SqlServerSqlNullabilityProcessor for JSON_CONTAINS
  • Fixes JsonScalarExpression handling for JSON constants/parameters with CAST to json type

Reviewed changes

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

Show a summary per file
File Description
src/EFCore.SqlServer/Infrastructure/Internal/ISqlServerSingletonOptions.cs Adds SupportsJsonContains property to the interface
src/EFCore.SqlServer/Infrastructure/Internal/SqlServerSingletonOptions.cs Implements SupportsJsonContains based on engine type and compatibility level
src/EFCore.SqlServer/Query/Internal/SqlServerQueryableMethodTranslatingExpressionVisitor.cs Implements TranslateContains to use JSON_CONTAINS for non-nullable primitive collections
src/EFCore.SqlServer/Query/Internal/SqlServerSqlNullabilityProcessor.cs Adds null-handling logic for JSON_CONTAINS function calls
src/EFCore.SqlServer/Query/Internal/SqlServerJsonPostprocessor.cs Adds CAST to json for JsonScalarExpression over constants to support RETURNING clause
test/EFCore.SqlServer.FunctionalTests/TestUtilities/SqlServerCondition.cs Adds SupportsJsonContains condition flag
test/EFCore.SqlServer.FunctionalTests/TestUtilities/SqlServerConditionAttribute.cs Implements check for SupportsJsonContains condition
test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs Adds IsJsonContainsSupported property for test environment detection
test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerJsonTypeTest.cs Updates test baselines for JSON_CONTAINS and removes explicit json column type configurations

@roji roji force-pushed the JsonContains branch 2 times, most recently from 3f7fb5f to f79bf36 Compare January 25, 2026 20:43
Copilot AI review requested due to automatic review settings January 25, 2026 20:43
@roji roji changed the title Implement JSON_CONTAINS() for non-nullable primitive collections Implement JSON_CONTAINS() for primitive collections Jan 25, 2026
Copy link

Copilot AI left a comment

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 11 out of 11 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings January 25, 2026 21:21
Copy link

Copilot AI left a comment

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 9 out of 9 changed files in this pull request and generated no new comments.

@roji roji enabled auto-merge (squash) January 26, 2026 08:10
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.

SQL Server: index over inline/constant list fails SQL Server: translate Contains over JSON primitive collections to the new JSON_CONTAINS()

1 participant