Skip to content

Update a null value on JSON column not working #33392

Closed as duplicate
Closed as duplicate

Description

@NikLuy

File a bug

When i update the column with a value i works well
But if there is an value in the column and i want to update with an null value the update is ignored on the json column everything else is updated.

Include your code

 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
     base.OnModelCreating(modelBuilder);

     modelBuilder.Entity<Charger>()
         .OwnsOne(c => c.Subjekt, s => s.ToJson())
         .OwnsOne(c => c.Zustell_Subjekt, s => s.ToJson());
  }
  
  public partial class Charger
 {
        [Key]
        public Guid Id { get; set; }
        public int? Id_Subjekt { get; set; }
        public int? Id_Zustelladresse { get; set; }
        public SubjektDto? Subjekt { get; set; }
        public SubjektDto? Zustell_Subjekt { get; set; }
 }
 
 public record SubjektDto
{
    public int? Id { get; set; }
    public string? Name { get; set; }
    public string? Vorname { get; set; }
    public string? Adresse { get; set; }
    public string? PLZ { get; set; }
    public string? Ort { get; set; }
    public string? Telefon { get; set; }
    public string? Email { get; set; }
    public int? SubjektTyp { get; set; }
    public string? Strasse { get; set; }
    public int? HausNr { get; set; }
    public string? HausNrZusatz { get; set; }
}

SELECT [Subjekt] FROM [dbo].[Chargers]
returns NULL

_db.Chargers.Update(charger); // with Value
await _db.SaveChangesAsync();

SELECT [Subjekt] FROM [dbo].[Chargers]
returns JSON

_db.Chargers.Update(charger); // with Null on Subjekt
await _db.SaveChangesAsync();

SELECT [Subjekt] FROM [dbo].[Chargers]
returns JSON

Activity

  1. roji commented on Mar 25, 2024

    @roji
    Member

    @ajcvickers not sure if you're the best person to investigate this or @maumar...

  2. roji commented on Mar 25, 2024

    @roji
    Member

    @NikLuy it would be helpful if you could submit a minimal, runnable code sample (i.e. console program) rather than the code snippets - that would help us investigate it much faster.

  3. NikLuy commented on Mar 26, 2024

    @NikLuy
    Author

    I work on it. The simple example workes as expected and updates the null values.
    So i have build a more complex example to reproduce the problem.

  4. NikLuy commented on Mar 26, 2024

    @NikLuy
    Author

    I Uploaded a simple API which has 4 Endpoints
    https://github.com/NikLuy/JsonDemo

  5. ajcvickers commented on Mar 26, 2024

    @ajcvickers
    Contributor
  6. removed their assignment
    on Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions