Fix NullReferenceException for SelectMany with inline array values#38286
Open
roji wants to merge 4 commits into
Open
Fix NullReferenceException for SelectMany with inline array values#38286roji wants to merge 4 commits into
roji wants to merge 4 commits into
Conversation
…e array values
When using SelectMany with an inline array where the collection values are
unreferenced (e.g. e => new[] { "a", "b" }.Select(k => e)), the values in the
ValuesExpression had no type mapping inferred from usage context. The
postprocessor then wrapped them in a Convert expression with null TypeMapping,
causing a NullReferenceException in QuerySqlGenerator.VisitSqlConstant.
Fix: In ApplyTypeMappingsOnValuesExpression, when no type mapping is inferred
from usage context, fall back to the default type mapping for the value's CLR
type.
Fixes #38285
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes a relational query pipeline crash by applying a fallback type mapping to inline VALUES expressions whose value column has no usage-inferred mapping.
Changes:
- Adds default CLR-type mapping fallback in
RelationalTypeMappingPostprocessor. - Adds a shared regression test for
SelectManyover unreferenced inline collection values. - Adds provider-specific expectations for SQL Server and SQLite.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/EFCore.Relational/Query/RelationalTypeMappingPostprocessor.cs |
Applies default type mappings to unmapped inline row values when inference is unavailable. |
test/EFCore.Specification.Tests/Query/PrimitiveCollectionsQueryTestBase.cs |
Adds the shared regression test for issue #38285. |
test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs |
Adds expected SQL for the new regression test. |
test/EFCore.Sqlite.FunctionalTests/Query/PrimitiveCollectionsQuerySqliteTest.cs |
Adds SQLite’s expected APPLY-not-supported behavior for the new test. |
- Add UnreachableException guards in QuerySqlGenerator.VisitSqlConstant and VisitSqlParameter for null TypeMapping, with message instructing users to file a bug report. - Simplify the type mapping fallback in ApplyTypeMappingsOnValuesExpression using coalesce. - Add missing test overrides for OldSqlServer, JsonType, and Cosmos providers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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 #38285
When using
SelectManywith an inline array where the collection values are unreferenced (e.g.e => new[] { "a", "b" }.Select(k => e)), the values in theValuesExpressionhad no type mapping inferred from usage context. The postprocessor then wrapped them in aConvertexpression with nullTypeMapping, causing aNullReferenceExceptioninQuerySqlGenerator.VisitSqlConstant.Fix: In
ApplyTypeMappingsOnValuesExpression, when no type mapping is inferred from usage context, fall back to the default type mapping for the value's CLR type.Generated SQL (SQL Server):