Skip to content

Commit

Permalink
Fix JsonValueReaderWriter check to support polymorphism (#3339)
Browse files Browse the repository at this point in the history
Fixes #3169

(cherry picked from commit 45c8227)
  • Loading branch information
roji committed Oct 29, 2024
1 parent 15ce73e commit 52e427f
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,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 52e427f

Please sign in to comment.