I have used "HasConversion" in my DBContext to define a JSonArray (Language/Value) and save it as a Text field for ages and It works like a charm, I added a new project to my solution, nothing changed but then I got a new error on adding migration regarding "setting a value comparer".
My Model is like:
public class Brand
{
public int Id { get; set; }
public new IList<LangValue> Name { get; set; } = new List<LangValue>();
}
and DBContext is like:
modelBuilder.Entity<Brand>(t =>
{
t.Property(p => p.Name).HasConversion(
v => JsonConvert.SerializeObject(v, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Include}),
v => JsonConvert.DeserializeObject<IList<LangValue>>(v, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Include})
);
});
It was working perfectly, but after adding a new project I got Yellow error in adding migration and Model does not add to the new database.
Microsoft.EntityFrameworkCore.Model.Validation[10620] The property 'Name' on entity type 'Brand' is a collection or enumeration type with a value converter but with no value comparer. Set a value comparer to ensure the collection/enumeration elements are compared correctly.