(SQL Server) EF Core 8 not respecting JsonIgnore
Hello, I have a json complex property that is being translated to json with
ToJson()
, some of the properties of the complex property can be null.
Now, I want those nullable properties when they are null, not to be written to the json representation.
I already tried to use JsonIgnoreAttribute
with Condition = JsonIgnoreCondition.WhenWritingNull
but EF Core ignores them for some reason.
Is there a special attribute that I can use or Fluent API for this behavior?
(model) https://pastebin.com/qHDFT4VTPastebin
public class Feedback{ public int Id { get; set; } public str...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
7 Replies
@Tost.NET This should do the trick!
Sadly that doesn't work as EF Core doesn't respect STJ options.
I found a similar issue thread on github tho so hopefully it'll be on EF9 resolved:
https://github.com/dotnet/efcore/issues/26981
GitHub
Cosmos: allow excluding null values from Json document · Issue #269...
When using [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonPropertyName("age")] public int? Age { get; set; } This still will create null when saving data in Cosmos Db ...
@Tost.NET I'm using ef core though.
How does your dto look like?
https://pastebin.com/qHDFT4VT
here's the model
Pastebin
public class Feedback{ public int Id { get; set; } public str...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
That's very weird. It's working fine for me.
You have set the properties to nullable. I don't really get it.
Let me check, If I have added some more configuration.
@Tost.NET Does cosmos return null as the actual value?
yes, in the picture provided above, I explicitly made "ClarityId" to be null, and it still persists it in the db
sorry for late reply, was on a meeting