我在我的 Windows Phone 通用应用程序中为 sqlite 使用 sqlite-net 我有以下具有表和列属性的类,并使用异步连接在 sqlite 中添加数据一切正常,但 Id 列不是自动递增的,也不是主要的钥匙。还有其他人面临这个问题吗?以下是我的代码。
[Table("Account")]
public class Account
{
[PrimaryKey, AutoIncrement]
[Column("Id")]
public int Id { get; set; }
[Column("FirstName")]
public string FirstName { get; set; }
[Column("LastName")]
public string LastName { get; set; }
[Ignore]
public string FullName { get; set; }
}
SQLite.SQLiteAsyncConnection conn = new SQLite.SQLiteAsyncConnection("database.sqlite");
var result = await conn.CreateTableAsync<Account>();
var _accountList = new Account();
_accountList.FirstName = "Name 1";
_accountList.LastName = "------------";
var result1 = await conn.InsertAsync(_accountList);
_accountList = new Account();
_accountList.FirstName = "Name 2";
_accountList.LastName = "------------";
result1 = await conn.InsertAsync(_accountList);
var list = await conn.Table<Account>().ToListAsync();
var item = list;
在读取所有记录的表 ID 时始终为 0。有没有什么办法解决这一问题?