macio.Jun
macio.Jun

Reputation: 9895

How to set default value for Sqlite.net without using sqlite raw statement/conn.execute()

I know it's a stupid question, but I could not find the answer anywhere. How to set a default value for a column in sqlite.net model? Here is my model class:

public class ItemTaxes
{
    [PrimaryKey]
    public string Sku { get; set;}
    public bool IsTaxable { get; set;}// How to set IsTaxable's default value to true?
    public decimal PriceTaxExclusive { get; set;}
}

I wanna set default value of Not Null column IsTaxable to true, how should I achieve that? Btw I do not want use raw sql statement, i.e. conn.execute();

Thank you.

Upvotes: 12

Views: 7243

Answers (2)

Aurast
Aurast

Reputation: 3688

If the Default attribute isn't available in the version of SQLite-net that you're using, you can use autoproperties to assign a default like you normally would.

public class ItemTaxes
{
    public bool IsTaxable { get; set; } = true;
}

Upvotes: 6

Gabriel Rainha
Gabriel Rainha

Reputation: 1743

A little late, but for those who got here looking for an answer:

public class ItemTaxes
{
    [NotNull, Default(value: true)]
    public bool IsTaxable { get; set; }
}

Upvotes: 11

Related Questions