Skip to content

Commit

Permalink
Handle Nullable<JsonElement>
Browse files Browse the repository at this point in the history
  • Loading branch information
Todd Aspeotis committed Dec 5, 2023
1 parent 0a795e3 commit 357a033
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ public class NpgsqlJsonElementHackConvention : IPropertyAddedConvention
public void ProcessPropertyAdded(IConventionPropertyBuilder propertyBuilder, IConventionContext<IConventionPropertyBuilder> 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));
}
}
}

0 comments on commit 357a033

Please sign in to comment.