Skip to content

Commit

Permalink
Fix JsonValueReaderWriter check to support polymorphism
Browse files Browse the repository at this point in the history
Fixes #3169
  • Loading branch information
roji committed Oct 29, 2024
1 parent 72cb52e commit a3ebace
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ private static RelationalTypeMappingParameters CreateParameters(string storeType
#pragma warning restore EF1001

var elementJsonReaderWriter = elementMapping.JsonValueReaderWriter;
if (elementJsonReaderWriter is not null && elementJsonReaderWriter.ValueType != typeof(TElement).UnwrapNullableType())
if (elementJsonReaderWriter is not null && !typeof(TElement).UnwrapNullableType().IsAssignableTo(elementJsonReaderWriter.ValueType))
{
throw new InvalidOperationException(
$"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()}').");
$"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}').");
}

// 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
Expand Down

0 comments on commit a3ebace

Please sign in to comment.