Skip to content

Create Table

jgiacomini edited this page Oct 1, 2017 · 11 revisions

Create Table

Create Table is easy in TinySQLite

The first thing you have to do is to create a POCO class which represent your table :

public class MyTable
{
    public string MyColumn1 { get; set; }
    public string MyColumn2 { get; set; }
}

You have just to call CreateTableAsync method.

var context = new DbContext(_pathOfDb);
var table = context.Table<MyTable>();
await table.CreateTableAsync();

Create a column with PRIMARY KEY

You have to put the attribute [PrimaryKey] on the column you want to have a PK.

public class PrimaryTable
{
     [PrimaryKey]
     public int Primary { get; set; }
}

Multiple primary key is allowed.

public class DoublePrimaryKey
{
    [PrimaryKey]
    public int Primary1 { get; set; }

    [PrimaryKey]
    public int Primary2 { get; set; }
}

Create an AUTOMINCREMENT column

Clone this wiki locally