Implement JSON_CONTAINS() for primitive collections#37562
Merged
roji merged 1 commit intodotnet:mainfrom Feb 5, 2026
Merged
Conversation
There was a problem hiding this comment.
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 |
test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerJsonTypeTest.cs
Show resolved
Hide resolved
3f7fb5f to
f79bf36
Compare
47e7384 to
d67292e
Compare
src/EFCore.SqlServer/Query/Internal/SqlServerJsonPostprocessor.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Query/Internal/SqlServerTypeMappingPostprocessor.cs
Show resolved
Hide resolved
src/EFCore.SqlServer/Query/Internal/SqlServerQueryableMethodTranslatingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Query/Internal/SqlServerQueryableMethodTranslatingExpressionVisitor.cs
Show resolved
Hide resolved
AndriySvyryd
reviewed
Feb 4, 2026
src/EFCore.SqlServer/Query/Internal/SqlServerJsonPostprocessor.cs
Outdated
Show resolved
Hide resolved
AndriySvyryd
reviewed
Feb 4, 2026
src/EFCore.SqlServer/Query/Internal/SqlServerJsonPostprocessor.cs
Outdated
Show resolved
Hide resolved
AndriySvyryd
approved these changes
Feb 4, 2026
This was referenced Feb 15, 2026
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.
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).Also includes some general improvements to how we handle JSON type mappings and literals.
Closes #36656
Fixes #37561