当前位置:首页 > 数据库 > SQlite

WF8&C#&SQLite&自动递增&失败

我尝试将SQLite库用于WP8.

我定义了一个表:

class ShoppingItem
{
  [SQLite.PrimaryKey]
  public int Id {get; set;}
  public string Name {get; set;}
  public string Shop {get; set;}
  public bool isActive {get; set;}
}

如果没有给出Id的值,根据sqlite自动将值分配给http://www.sqlite.org/autoinc.html.对?

所以我尝试通过插入新条目

using (var db = new SQLiteConnection(m_DatabasePath)) {
    db.Insert(new ShoppingItem() {
      Name = anItem,
      Shop = aShop,
      isActive = aIsActive,
    });
}

当我插入第一个项目时,它的ID为0.那么,为什么不呢?
当我插入第二个项目时,我得到一个带有超赞消息“ Constraint”的SQLiteException.
那么,如何在不提供ID的情况下插入新条目?

顺便说一句:
作为一种替代解决方案,我尝试向id添加一个null值,但这导致了编译错误.


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!