From df0737e55afeb5c01eb39909605970d1d3a73ffc Mon Sep 17 00:00:00 2001 From: Melodi <62381002+Melodi17@users.noreply.github.com> Date: Sun, 13 Sep 2026 13:22:20 +1000 Subject: refactor: cleanup; feat: connection to agent --- src/marlin.web/Data/JsonValueComparer.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/marlin.web/Data/JsonValueComparer.cs (limited to 'src/marlin.web/Data/JsonValueComparer.cs') diff --git a/src/marlin.web/Data/JsonValueComparer.cs b/src/marlin.web/Data/JsonValueComparer.cs new file mode 100644 index 0000000..f07c133 --- /dev/null +++ b/src/marlin.web/Data/JsonValueComparer.cs @@ -0,0 +1,23 @@ +namespace marlin.web.Data; + +using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.ChangeTracking; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +public static class JsonValueComparer +{ + public static ValueComparer Create() => new( + (a, b) => JsonSerializer.Serialize(a, (JsonSerializerOptions?)null) == JsonSerializer.Serialize(b, (JsonSerializerOptions?)null), + v => JsonSerializer.Serialize(v, (JsonSerializerOptions?)null).GetHashCode(), + v => JsonSerializer.Deserialize(JsonSerializer.Serialize(v, (JsonSerializerOptions?)null), (JsonSerializerOptions?)null)!); +} + +public static class PropertyBuilderExtensions +{ + public static PropertyBuilder HasJsonConversion(this PropertyBuilder builder) => + builder.HasConversion( + v => JsonSerializer.Serialize(v, (JsonSerializerOptions?)null), + v => JsonSerializer.Deserialize(v, (JsonSerializerOptions?)null)!, + JsonValueComparer.Create()); +} -- cgit v1.3.1