You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once Children is persisted as [], I cannot set it to null.
//insert entityusing(MyContextcontext=new()){ParentEntityparent=new(){Id=id,Name="A",Children=[]//set Children to empty list};
context.Parents.Add(parent);await context.SaveChangesAsync();}//read and update entityusing(MyContextcontext=new()){varparent=await context.Parents.FindAsync(id);parent!.Name ="B";
parent.Children =null;//set Children to null;await context.SaveChangesAsync();//SQL update statement doesn't update parent.Children}
It seems to me like the change tracking doesn't recognize the change from [] to null as a relevant change. If I understand #31831 correctly, [] and null should be considered distinct.
EF Core version: 8.0.3
Database provider: Microsoft.EntityFrameworkCore.Sqlite 8.0.3 (and Npgsql.EntityFrameworkCore.PostgreSQL 8.0.2)
Target framework: net8.0
IDE: Visual Studio 2022 17.9.5
The text was updated successfully, but these errors were encountered:
I can confirm this behavior too. Just recently, I changed all JSON collection properties to non-nullable, since it was confusing for the teams not to be able to set it to null.
Btw, no matter if you annotate the collection property as nullable or non-nullable, the underlying db column is always defined as nullable. Not sure if that's by design or if it's a bug. Until recently, collections were never mapped to columns, so I guess this is an artifact of that.
I have an entity with an owned, nullable JSON collection (see NullVsEmptyList.zip for a running example):
Once
Children
is persisted as[]
, I cannot set it tonull
.Here's the generated SQL update statement:
It seems to me like the change tracking doesn't recognize the change from
[]
tonull
as a relevant change. If I understand #31831 correctly,[]
andnull
should be considered distinct.EF Core version: 8.0.3
Database provider: Microsoft.EntityFrameworkCore.Sqlite 8.0.3 (and Npgsql.EntityFrameworkCore.PostgreSQL 8.0.2)
Target framework: net8.0
IDE: Visual Studio 2022 17.9.5
The text was updated successfully, but these errors were encountered: