79267295

Date: 2024-12-10 07:11:10
Score: 0.5
Natty:
Report link

EF Core doesn’t automatically know how to save a List in the database. By default, it tries to use a database array type (text[] in PostgreSQL). However, this doesn’t match well with EF Core’s internal handling, especially when combined with default values.

    builder.Entity<User>()
.Property(u => u.PasswordHistory)
.HasConversion(
    v => JsonSerializer.Serialize(v, (JsonSerializerOptions?)null),
    v => JsonSerializer.Deserialize<List<string>>(v, (JsonSerializerOptions?)null) ?? new List<string>()
);
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Pavithra