Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 256
macio.Jun Avatar asked Sep 08 '14 17:09

macio.Jun


2 Answers

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; }
}
like image 192
Gabriel Rainha Avatar answered Oct 01 '22 20:10

Gabriel Rainha


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;
}
like image 40
Aurast Avatar answered Oct 01 '22 20:10

Aurast