[release/10.0] Fix issues with nulls in primitive collections#38066
Open
cincuranet wants to merge 1 commit intodotnet:release/10.0from
Open
[release/10.0] Fix issues with nulls in primitive collections#38066cincuranet wants to merge 1 commit intodotnet:release/10.0from
cincuranet wants to merge 1 commit intodotnet:release/10.0from
Conversation
There was a problem hiding this comment.
Pull request overview
Backports the fix for queries using EF.Parameter() over primitive collections containing null, preventing runtime InvalidCastException by rewriting the parameterized collection and adjusting SQL null semantics handling.
Changes:
- Added specification and provider-specific functional tests covering
EF.Parameter(nullableInts).Contains(...)when the collection containsnull. - Updated relational nullability processing to preserve the original collection element CLR type when rewriting parameters to remove
nullelements (with an AppContext switch for old behavior). - Updated SQL Server nullability processing to use non-nullable element CLR types for OPENJSON value columns (with an AppContext switch for old behavior).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/EFCore.Specification.Tests/Query/PrimitiveCollectionsQueryTestBase.cs | Adds the new cross-provider test for EF.Parameter() over nullable int collections containing null. |
| test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs | Adds SQL assertion covering null-stripping parameter rewrite and OR ... IS NULL compensation. |
| test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServer160Test.cs | Same SQL assertion coverage for SQL Server 160 test variant. |
| test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerJsonTypeTest.cs | Adds SQL assertion coverage for JSON type mapping variant (parameter size differences). |
| test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQueryOldSqlServerTest.cs | Asserts expected failure mode on older SQL Server versions where EF.Parameter primitive collection translation isn’t supported. |
| test/EFCore.Sqlite.FunctionalTests/Query/PrimitiveCollectionsQuerySqliteTest.cs | Adds SQLite SQL assertion for null-stripping rewrite and OR ... IS NULL compensation. |
| test/EFCore.Cosmos.FunctionalTests/Query/PrimitiveCollectionsQueryCosmosTest.cs | Adds Cosmos SQL assertion ensuring null is preserved in the array parameter. |
| src/EFCore.Relational/Query/SqlNullabilityProcessor.cs | Fixes parameter-rewrite element type selection to preserve original element CLR type (value-converter-sensitive), with compatibility switch. |
| src/EFCore.SqlServer/Query/Internal/SqlServerSqlNullabilityProcessor.cs | Adjusts OPENJSON value column CLR type selection to avoid nullable element types unless compatibility switch is enabled. |
roji
approved these changes
Apr 9, 2026
artl93
approved these changes
Apr 9, 2026
Member
artl93
left a comment
There was a problem hiding this comment.
Customer reported regression. Approved.
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.
Backport of #37674.
Fixes #37537.
Description
When parameter collection contains
nullvalue EF Core attempts to convert a null value from the collection into a non-nullable underlying type during the command execution phase resulting inInvalidCastException.Customer impact
Query fails to execute.
How found
Customer reported on 10.0.
Regression
Yes.
Testing
Tests added.
Risk
Low. Quirk added.