I need the primary key to start from 1000 .how can do it?
public class LoginTable
{
[PrimaryKey, AutoIncrement, Column("_Id")]
public int id { get; set; }
public string info { get; set; }
public string info2 { get; set; }
}
I need the primary key to start from 1000 .how can do it?
public class LoginTable
{
[PrimaryKey, AutoIncrement, Column("_Id")]
public int id { get; set; }
public string info { get; set; }
public string info2 { get; set; }
}
You can modify the sqlite_sequence
table and assign whatever starting point you want. If the LoginTable
has not been inserted into, you will need to insert a new sqlite_sequence
record, otherwise you would need to update the existing sqlite_sequence
record.
The sqlite_sequence
contains just two fields (name
and seq
) and does not contain a primary key nor any indexes. name
is name of your table and seq
is the current used sequence number, the next insert would increment this BEFORE using it.
using (var db = new SQLiteConnection("foo.sqlite"))
{
db.CreateTable<LoginTable>();
db.Execute("insert into sqlite_sequence (name, seq) values (?, ?);", new object[] { "LoginTable", 999 });
// if LoginTable records already exist, then the `sqlite_sequence` record exists for this table and you need to update it...
//db.Execute("update sqlite_sequence set seq = ? where name = ?;", new object[] { 999, "LoginTable"});
var login = new LoginTable { info = "info1....", info2 = "info2....." };
db.Insert(login);
db.Insert(login);
db.Insert(login);
foreach (var item in db.Table<LoginTable>())
{
Console.WriteLine(item.id);
}
}
1000
1001
1002