So given a simple model
public class Foo
{
public int Id {get; set;}
public string A {get; set;}
public string B {get; set;}
}
And a Patch DTO to Update the model
public class UpdateFoo : IReturn<Foo>
{
public int Id {get; set;}
public Foo foo {get; set;}
}
… Is there a clean way to clear out a particular field of a model? For instance, I can handle normal updates by doming something like:
public Foo Any(UpdateFoo request)
{
var foo = Db.SingleById<Foo>(request.Id);
foo.PopulateWithNonDefaultValues(request.Foo);
Db.Save(foo);
return Db.SingleById<Foo>(request.Id);
}
This works fine for updates with new/changed data, but what if I want to flow a null, i.e. clear out a field? With the DTO the way I have it above, ServiceStack won’t be able to tell which field the client explicitly set to null. My searching online suggested changing my DTO to use a JSONPatch pattern, but I was wondering if there was a better way to do this.