Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a default value for a column in SQLite using SQLite-net?

I'm importing an Android code to windows rt and I need the data to be compatible on both apps. When creating my sqlite database I need to set a default value to a column, doing something like

CREATE TABLE [blabla] ( [id] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, [bleh] INTEGER NOT NULL DEFAULT -1 )

I wrote my C# code, using SQLite-net this way:

[Table("blabla")]
public class Blabla {
    [PrimaryKey, AutoIncrement, NotNull]
    public int id { get; set; }

    [NotNull]
    public int bleh { get; set; }
}

But I can't set the default value to 'bleh'. I need both database to be the same =/ Can anyone help me with this?

Thanks =)

like image 729
Massita Avatar asked Dec 04 '25 17:12

Massita


1 Answers

Why don't you use:

    private int _bleh = 1;
    [NotNull]
    public int Bleh
    {
        get { return _bleh; }
        set { _bleh = value; }
    }

Then bleh will always have a default of 1 unless changed

like image 52
User1 Avatar answered Dec 06 '25 07:12

User1



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!