Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with null values on schemafull tables #95

Open
armandoradan opened this issue Apr 3, 2024 · 2 comments
Open

Problem with null values on schemafull tables #95

armandoradan opened this issue Apr 3, 2024 · 2 comments

Comments

@armandoradan
Copy link

armandoradan commented Apr 3, 2024

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,

@Odonno
Copy link
Contributor

Odonno commented Apr 3, 2024

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]

@armandoradan
Copy link
Author

Thank you @Odonno

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants