-
Notifications
You must be signed in to change notification settings - Fork 22
Partial Updates
Unlike JavaScript, C# does not have an undefined value, so that, when deserializing, the values that are not present in source Json are set to default().
That could be a problem if default is a valid value for the business logic!
Clr .NET primitives, such as boolean, int, etc. can be turned into Nullable<>, so, for example if int x = 0 (zero) is a valid value, then int? x = null can be safely used as undefined.
Drawback of using nullables is that the value may not be optional in the database, but only for the update operation that is being performed. So that there is a risk of having invalid values stored, an a complexity of checking for null values everywhere when no null value is expected.
(i.e. int User.Age is not optional, but in an update operation you don't want to change it, so you send null)
For relationships, null means removing the reference, even deleting the child entity if cascade is set. So using null as undefined is not an option. Here we want to analyze some alternatives.