Can AutoQuery.Patch set a value to null?

Is it possible to use AutoQuery.Patch() to set a MSSQL database column to null?

I have been using Patch to set (true) or clear (false) a “Closed” boolean column. But, I now need to also set/clear a “ClosedDate” column. Unfortunately, having ClosedDate = null in the Patch does not set the database column to null.

Yeah you can specify the column names to reset back to their default value in a Reset string collection property, e.g. here’s a test example for resetting field values:

public class PatchDefaultValues : IPatchDb<DefaultValue>, IReturnVoid
{
    public int Id { get; set; }
    public int Int { get; set; }
    public int? NInt { get; set; }
    public bool Bool { get; set; }
    public bool? NBool { get; set; }
    public string String { get; set; }
    public string[] Reset { get; set; }
}

var request = new PatchDefaultValues {
    Id = createRequest.Id,
    Reset = new[] {
        nameof(PatchDefaultValues.Bool),
        nameof(PatchDefaultValues.NBool),
        nameof(PatchDefaultValues.Int),
        nameof(PatchDefaultValues.NInt),
        nameof(PatchDefaultValues.String),
    },
};
client.Patch(request);

Perfect. Works like a charm. Thank you.

1 Like