Skip to content

Commit 890e652

Browse files
authored
Allow mapping multidim arrays to json/jsonb again (#3663)
Fixes #3652
1 parent dc09158 commit 890e652

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,12 +745,18 @@ public NpgsqlTypeMappingSource(
745745
// However, when scalar collections are nested inside a JSON document, they obviously have to be JSON-mapped.
746746
// In addition, at least in theory users may decide to map to JSON instead of array even outside JSON documents.
747747
case "jsonb" or "json" when modelClrType is not null:
748-
return base.FindCollectionMapping(
748+
var mapping = base.FindCollectionMapping(
749749
new RelationalTypeMappingInfo(
750750
modelClrType, (RelationalTypeMapping?)elementMapping, storeTypeName: storeType, storeTypeNameBase: storeType),
751751
modelClrType,
752752
providerClrType,
753753
elementMapping);
754+
755+
// If a multidimensional array is mapped to json/jsonb, we get here, and base.FindCollectionMapping happily returns a
756+
// "primitive" collection whose element mapping is an array; but EF does not support nested primitive collections.
757+
// So we return null to let the calling code in FindBaseMapping simply return an NpgsqlJsonTypeMapping with no
758+
// ElementTypeMapping - this case isn't at all handled as an EF primitive collection, but as an opaque JSON type.
759+
return mapping is { ElementTypeMapping: NpgsqlArrayTypeMapping } ? null : mapping;
754760
#pragma warning restore EF1001 // SelectExpression constructors are pubternal
755761

756762
default:

0 commit comments

Comments
 (0)