Skip to content

[release/10.0] Fix issues with nulls in primitive collections#38066

Open
cincuranet wants to merge 1 commit intodotnet:release/10.0from
cincuranet:backport-37674
Open

[release/10.0] Fix issues with nulls in primitive collections#38066
cincuranet wants to merge 1 commit intodotnet:release/10.0from
cincuranet:backport-37674

Conversation

@cincuranet
Copy link
Copy Markdown
Contributor

@cincuranet cincuranet commented Apr 9, 2026

Backport of #37674.
Fixes #37537.

Description

When parameter collection contains null value EF Core attempts to convert a null value from the collection into a non-nullable underlying type during the command execution phase resulting in InvalidCastException.

Customer impact

Query fails to execute.

How found

Customer reported on 10.0.

Regression

Yes.

Testing

Tests added.

Risk

Low. Quirk added.

@cincuranet cincuranet requested a review from a team as a code owner April 9, 2026 08:08
Copilot AI review requested due to automatic review settings April 9, 2026 08:08
@cincuranet cincuranet self-assigned this Apr 9, 2026
Copy link
Copy Markdown

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

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 contains null.
  • Updated relational nullability processing to preserve the original collection element CLR type when rewriting parameters to remove null elements (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.

@cincuranet cincuranet requested a review from artl93 April 9, 2026 08:14
Copy link
Copy Markdown
Member

@artl93 artl93 left a comment

Choose a reason for hiding this comment

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

Customer reported regression. Approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants