使用WP8的SQLite让我感到非常沮丧。:(
我想做的就是检索最后插入id的值...
我已经有了:
class ShoppingItem
{
[SQLite.PrimaryKey, SQLite.AutoIncrement]
public int Id {get; set;}
public string Name {get; set;}
public string Shop {get; set;}
public bool isActive {get; set;}
}
嗯,看起来既使用过的SQLiteConnection
对象也是它的Table<ShoppingItem>
似乎都没有适当的成员包含最后一个ID。
所以我尝试:
private int GetLastInsertedRowID()
{
int Result = -1;
using (var db = new SQLiteConnection(m_DatabasePath)) {
Result = db.ExecuteScalar<int>("SELECT last_insert_rowid();");
}
return Result;
}
但是这个函数总是返回
0
。 :(
但是当我读取所有ShoppingItem
的条目时,它们的ID具有 != 0 的值。所以我的问题是:如何检索最后插入的ID?
PS:将SQL查询更改为
SELECT last_insert_rowid() FROM ShoppingItem;
得到了相同的结果。PPS:像在C#中使用SQLite.NET获取最后插入ID这样的解决方案不会编译,显然使用的是旧版本的SQLite,其API完全不同。