Skip to content

Commit c217da3

Browse files
rojiWhatzGames
authored andcommitted
Fix JsonValueReaderWriter check to support polymorphism (npgsql#3339)
Fixes npgsql#3169
1 parent 89476a7 commit c217da3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/EFCore.PG/Storage/Internal/Mapping/NpgsqlArrayTypeMapping.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ private static RelationalTypeMappingParameters CreateParameters(string storeType
142142
#pragma warning restore EF1001
143143

144144
var elementJsonReaderWriter = elementMapping.JsonValueReaderWriter;
145-
if (elementJsonReaderWriter is not null && elementJsonReaderWriter.ValueType != typeof(TElement).UnwrapNullableType())
145+
if (elementJsonReaderWriter is not null && !typeof(TElement).UnwrapNullableType().IsAssignableTo(elementJsonReaderWriter.ValueType))
146146
{
147147
throw new InvalidOperationException(
148-
$"When building an array mapping over '{typeof(TElement).Name}', the JsonValueReaderWriter for element mapping '{elementMapping.GetType().Name}' is incorrect ('{elementMapping.JsonValueReaderWriter?.GetType().Name ?? "<null>"}' instead of '{typeof(TElement).UnwrapNullableType()}').");
148+
$"When building an array mapping over '{typeof(TElement).Name}', the JsonValueReaderWriter for element mapping '{elementMapping.GetType().Name}' is incorrect ('{elementJsonReaderWriter.ValueType.GetType().Name}' instead of '{typeof(TElement).UnwrapNullableType()}', the JsonValueReaderWriter is '{elementJsonReaderWriter.GetType().Name}').");
149149
}
150150

151151
// If there's no JsonValueReaderWriter on the element, we also don't set one on its array (this is for rare edge cases such as

0 commit comments

Comments
 (0)