dotnet / dotnet/EntityFramework.Docs

Document updating a JSON mapped column with a required property

Open
#4,514 2 comments 0 reactions 0 assignees View on GitHub
area-model-building
Dominant language
Mermaid
Stars
1.7k
Forks
2k
Avg merge
7d 23h
Merged PRs (30d)
16

Description

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.

```C#
public class MyClass {
// registered as a json column inside the dbcontext
public required List 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.