Fix issues with nulls in primitive collections#37674
Merged
roji merged 1 commit intodotnet:mainfrom Feb 12, 2026
Merged
Conversation
6 tasks
There was a problem hiding this comment.
Pull request overview
Fixes incorrect/null-unaware translation and execution for Contains over nullable primitive collections (especially when SQL Server switches to OPENJSON), ensuring correct matching of NULL elements and avoiding invalid nullable SqlExpression types.
Changes:
- Update relational null-stripping logic to preserve the original collection element CLR type when rewriting parameters (to keep value converters working correctly).
- Fix SQL Server
OPENJSONColumnExpressionconstruction to use a non-nullable CLR type while keeping nullability in the separatenullableflag. - Add/adjust provider functional tests (SqlServer/Sqlite/Cosmos) for
EF.Parameter(...).Contains(...)and add large-collection regression coverage for #37605.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/EFCore.Sqlite.FunctionalTests/Query/PrimitiveCollectionsQuerySqliteTest.cs | Adds SQL assertion for EF.Parameter + nullable ints including null semantics (OR ... IS NULL). |
| test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs | Adds SQL assertion for OPENJSON + OR ... IS NULL, plus large collection regression test; file also appears to have gained a BOM. |
| test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerJsonTypeTest.cs | Adds SQL assertion for OPENJSON + OR ... IS NULL in JSON-type variant. |
| test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServer160Test.cs | Adds SQL assertion for OPENJSON + OR ... IS NULL for SQL Server 2016+ coverage. |
| test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQueryOldSqlServerTest.cs | Adds an override expecting EF.Parameter unsupported and adds a large-collection regression test. |
| test/EFCore.Specification.Tests/Query/PrimitiveCollectionsQueryTestBase.cs | Introduces new base test for EF.Parameter(nullableInts).Contains(...) with a null element. |
| test/EFCore.Cosmos.FunctionalTests/Query/PrimitiveCollectionsQueryCosmosTest.cs | Adds Cosmos SQL assertion for EF.Parameter over nullable ints including null. |
| src/EFCore.SqlServer/Query/Internal/SqlServerSqlNullabilityProcessor.cs | Ensures ColumnExpression type is non-nullable for OPENJSON projection; file also appears to have gained a BOM. |
| src/EFCore.Relational/Query/SqlNullabilityProcessor.cs | Rewrites null-stripping to pick element type from runtime IEnumerable<T> to preserve converter expectations. |
test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Query/Internal/SqlServerSqlNullabilityProcessor.cs
Outdated
Show resolved
Hide resolved
21e9bcf to
47b9700
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs:1
- This file now starts with a UTF-8 BOM (invisible character before the first
//). Unless the file contains non-ASCII characters that require it, please revert the BOM/encoding-only change to avoid unnecessary diffs and inconsistent encodings across the repo.
// Licensed to the .NET Foundation under one or more agreements.
src/EFCore.SqlServer/Query/Internal/SqlServerSqlNullabilityProcessor.cs:1
- This file now starts with a UTF-8 BOM (invisible character before the license header). Unless there are non-ASCII characters in the file, please remove the BOM to avoid encoding-only churn and keep file encodings consistent.
// Licensed to the .NET Foundation under one or more agreements.
AndriySvyryd
approved these changes
Feb 12, 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.
Fixes #37605
Thanks to @BurakBebek1 for flagging this and submitting a fix PR in #37600.