From 52e427f623d019f1cefeeb55af109bb0170024a3 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Tue, 29 Oct 2024 17:20:18 +0100 Subject: [PATCH] Fix JsonValueReaderWriter check to support polymorphism (#3339) Fixes #3169 (cherry picked from commit 45c82278109f56ec11076e2e7b93d1ff77a097f4) --- .../Storage/Internal/Mapping/NpgsqlArrayTypeMapping.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlArrayTypeMapping.cs b/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlArrayTypeMapping.cs index b986d9122..777778ad0 100644 --- a/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlArrayTypeMapping.cs +++ b/src/EFCore.PG/Storage/Internal/Mapping/NpgsqlArrayTypeMapping.cs @@ -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 ?? ""}' 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