Db.Save ignore valued property if [Default] attribute is specified

Hi,

this is my POCO

public class LRDRisultato : IHasId<int>
{
    [Alias("IDDRISULTATO")]
    [AutoIncrement]
    public int Id { get; set; }

    [Alias("CODICE")]
    [StringLength(50)]
    public string Codice { get; set; }

    [Alias("NUMERODECIMALI")]
    [Default(-1)]
    public int NumeroDecimali { get; set; }

    [Alias("VISUALIZZAONLINE")]
    [Default(1)]
    public int VisualizzaOnLine { get; set; }
}

I create a service to allow CRUD operations, then I
send the following json to create a new item

{
“codice”: “CONC”,
“numeroDecimali”: 4,
“visualizzaOnLine”: 0
}

After Db.Save(obj) is executed the table field visualizzaOnLine is valued to 1 whilst numeroDecimali is valued to 4. I expect visualizzaOnLine valued to 0 as the json states.

visualizzaOnLine is missing in Db.LastCommandText whilst numeroDecimali is there.

Which is the right way to use Default attribute?

The value of 0 is the default(int) which is considered to have no value. Don’t use [Default] if you don’t want this behaviour.

Ok, but why I get the same behaviour if I change int to nullable int?

public int? VisualizzaOnLine { get; set; }

When SS deserializer deserializes this json
{
“codice”: “CONC”,
“numeroDecimali”: 4,
}

object.visualizzaOnLine equals to null and SS correctly saves1

When SS deserializer deserializes this json
{
“codice”: “CONC”,
“numeroDecimali”: 4,
“visualizzaOnLine”: 0
}

object.visualizzaOnLine equals to 0 but SS saves 1, it seems a bit misleading.

0 is still the default(int) - don’t use [Default] if you want to save default(int) values.