-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Implement JSON_CONTAINS() for primitive collections #37562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerJsonTypeTest.cs
Show resolved
Hide resolved
3f7fb5f to
f79bf36
Compare
There was a problem hiding this 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.
There was a problem hiding this 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.
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