surrealdb.net icon indicating copy to clipboard operation
surrealdb.net copied to clipboard

Problem with null values on schemafull tables

Open armandoradan opened this issue 10 months ago • 2 comments

I have created a schemafull table with an optional field (option) and mapped a C# object to it. But when I try to insert new records using Upsert or Create, if the value is null, the process fails! It doesn't provide any useful information other that throwing a 'SurrealDb.Net.Exceptions.SurrealDbErrorResultException' , but it might be because surrealdb expects 'NONE' for empty fields and the .NET SDK tries to send 'NULL' instead,

armandoradan avatar Apr 03 '24 15:04 armandoradan

Hello @armandoradan

You are correct. Default value for class objects are null which is different than NONE in the SurrealDB world. You can use the [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] or [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] attribute on your properties so that it will never be in the JSON payload, then being treated as NONE.

I suppose the only missing part would be to force to NONE on merge/patch method. I have plan to add custom attributes to handle the different use cases (also being agnostic to the serialization format). Custom attributes could have the form of:

  • [IgnoreIfNull]
  • [IgnoreIfDefault]
  • [TreatAsNoneIfNull]
  • [TreatAsNoneIfDefault]

Odonno avatar Apr 03 '24 15:04 Odonno

Thank you @Odonno

armandoradan avatar Apr 03 '24 18:04 armandoradan