我需要主键从 1000 开始。怎么办?
public class LoginTable
{
[PrimaryKey, AutoIncrement, Column("_Id")]
public int id { get; set; }
public string info { get; set; }
public string info2 { get; set; }
}
我需要主键从 1000 开始。怎么办?
public class LoginTable
{
[PrimaryKey, AutoIncrement, Column("_Id")]
public int id { get; set; }
public string info { get; set; }
public string info2 { get; set; }
}
您可以修改sqlite_sequence
表格并分配您想要的任何起点。如果LoginTable
尚未插入,则需要插入新sqlite_sequence
记录,否则需要更新现有sqlite_sequence
记录。
sqlite_sequence
仅包含两个字段 (name
和seq
),并且不包含主键或任何索引。name
是您的表的名称,并且seq
是当前使用的序列号,下一个插入将在使用它之前增加它。
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