JSON serialization Value Conversion not tracking changes with EF Core JSON serialization Value Conversion not tracking changes with EF Core json json

JSON serialization Value Conversion not tracking changes with EF Core


I was able to get change tracking to kick in by adding a ValueConverter and a ValueComparer to the Metadata of the property, however, my comparer is probably very inefficient. If anyone has suggestions on performance tuning for this, it would be much appreciated.

mb.Entity<MyObject>().Property(p => .MySerializableObject).HasJsonConversion();

With the new HasJsonConversion extension method

public static class ValueConversionExtensions{    public static PropertyBuilder<T> HasJsonConversion<T>(this PropertyBuilder<T> propertyBuilder)    {                   ValueConverter<T, String> converter = new ValueConverter<T, String>(            v => JsonConvert.SerializeObject(v),            v => JsonConvert.DeserializeObject<T>(v));        ValueComparer<T> comparer = new ValueComparer<T>(            (l, r) => JsonConvert.SerializeObject(l) == JsonConvert.SerializeObject(r),            v => v == null ? 0 : JsonConvert.SerializeObject(v).GetHashCode(),            v => JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(v)));        propertyBuilder.HasConversion(converter);        propertyBuilder.Metadata.SetValueConverter(converter);        propertyBuilder.Metadata.SetValueComparer(comparer);                    return propertyBuilder;    }        }