Document updating a JSON mapped column with a required property
I have a type which already exists in my database. We've expanded this type and added new required properties to it. However this causes the deserialization to fail since these properties do no yet exist on existing rows.
Below is a small example of my scenario. How would I go about updating the existing rows/data to match the new contract? Setting default values does not seem to help since the deserialization process will fail before it.
public class MyClass {
// registered as a json column inside the dbcontext
public required List<MyRecord> Records { get; set; }
}
public record MyRecord
{
public required Guid Identifier { get; set; }
public required string Title { get; set; }
// Below properties are new
public required bool IsDeleted { get; set; } = false;
public required DateTimeOffset? DeletedAt { get; set; } = null;
provider and version information
EF Core version: 7.0.11 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET 7.0 Operating system: Win11 IDE: Rider 2023.2.1
If you want to use EF start to finish, you can make the new properties optional at first, then load all the entities, add values for those new properties, save changes and then make the properties required.
Note from triage: document