-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix issues with nulls in primitive collections #37674
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
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.
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.
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.
Fixes #37605
Thanks to @BurakBebek1 for flagging this and submitting a fix PR in #37600.