diff --git a/src/EFCore.PG/Metadata/Conventions/NpgsqlJsonElementHackConvention.cs b/src/EFCore.PG/Metadata/Conventions/NpgsqlJsonElementHackConvention.cs index df2fb162a..02d8c0fc1 100644 --- a/src/EFCore.PG/Metadata/Conventions/NpgsqlJsonElementHackConvention.cs +++ b/src/EFCore.PG/Metadata/Conventions/NpgsqlJsonElementHackConvention.cs @@ -20,10 +20,11 @@ public class NpgsqlJsonElementHackConvention : IPropertyAddedConvention public void ProcessPropertyAdded(IConventionPropertyBuilder propertyBuilder, IConventionContext context) { var property = propertyBuilder.Metadata; + var clrType = property.ClrType; - if (property.ClrType == typeof(JsonElement) && property.GetColumnType() is null) + if ((clrType == typeof(JsonElement) || clrType == typeof(JsonElement?)) && property.GetColumnType() is null) { - property.SetTypeMapping(_jsonTypeMapping ??= new NpgsqlJsonTypeMapping("jsonb", typeof(JsonElement))); + property.SetTypeMapping(_jsonTypeMapping ??= new NpgsqlJsonTypeMapping("jsonb", clrType)); } } }