Fix CreateParameter for collection shape mismatch with element value converters - #3894
Open
hostage2222 wants to merge 1 commit into
Open
Fix CreateParameter for collection shape mismatch with element value converters#3894hostage2222 wants to merge 1 commit into
hostage2222 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a failure in array parameter creation when an element value converter is present and the parameter value’s collection shape doesn’t match the inferred mapping shape (e.g. List<T> passed where an T[] mapping is applied), which previously could cause ValueConverter.Sanitize to throw InvalidCastException (notably in Intersect(...).Any() translated to &&).
Changes:
- Update
NpgsqlArrayTypeMapping.CreateParameterto normalize non-matching values to the supported concrete collection shape (array orList<T>) even when a converter exists, but without rewriting values that already match the converter’s model CLR type. - Add unit tests covering
CreateParameterwith value converters across array/list/immutable-list inputs. - Add functional tests covering
Intersect(...).Any()over value-converted primitive collections with array/list/immutable-list parameters.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/EFCore.PG/Storage/Internal/Mapping/NpgsqlArrayTypeMapping.cs | Normalizes mismatched collection-shape parameter values prior to converter sanitization to avoid invalid casts. |
| test/EFCore.PG.Tests/Storage/NpgsqlTypeMappingSourceTest.cs | Unit coverage for CreateParameter behavior across list/array/immutable-list inputs with converters. |
| test/EFCore.PG.FunctionalTests/Query/ArrayListQueryTest.cs | Functional coverage for Intersect(...).Any() over a value-converted list when the parameter shape varies. |
| test/EFCore.PG.FunctionalTests/Query/ArrayArrayQueryTest.cs | Functional coverage for Intersect(...).Any() over a value-converted array when the parameter shape varies. |
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.
When a primitive collection has an element value converter and a parameter uses a different collection shape (e.g. List vs T[]), type mapping inference for Intersect(...).Any() → && can apply the column mapping to that parameter. CreateParameter skipped materialization whenever a converter was present, so Sanitize threw InvalidCastException (IConvertible).
Normalize mismatched values to TConcreteCollection before Sanitize, without rewriting values that already match the converter model type. There is no extra materialization on existing paths — only the new mismatch cases take that branch; existing tests do not.
Fixes #3805