SQLite-net-pcl - Always returning ID as 0 (Xamarin)

Phi*_*ins 6 xamarin sqlite-net sqlite-net-extensions

I recently moved across from SQLite.NET to SQLite-net-pcl due to the Android 7.0 SQlite issue.

In the process I have updated all my libraries and all is working well with regards to insert/drop etc.

我唯一的问题是,每次从数据库中检索项目时,它的ID始终为0。这会导致更新项目的问题。有人遇到过这个问题吗?

 [SQLite.PrimaryKey, SQLite.AutoIncrement]
    public int ID { get; set; }
    public string objectId { get; set; }
    public DateTime createdAt { get; set; }
    public DateTime updatedAt { get; set; }
    public string Title { get; set; }
Run Code Online (Sandbox Code Playgroud)

提前致谢。

小智 5

请尝试使用这个,这对我有用

使用 SQLite.Net.Attributes;

  [PrimaryKey, AutoIncrement]
    public int? Id { get; set; }
Run Code Online (Sandbox Code Playgroud)


小智 0

CreateComand(query)查看是否使用方法和创建了表ExecuteNonQuery()。如果是这种情况,请使用该CreateTable<Type>()方法创建表。通过上述方法在建表时初始化主键和自增属性