
上QQ阅读APP看书,第一时间看更新
Updating the TodoItem class
Since SQLite is a relational database, it needs to know some basic information about how to create the tables that will store our objects. This is done using attributes, which are defined in the SQLite namespace:
- Open up the Models/TodoItem.
- Add a using SQLite statement at the start of the file right below the existing using statements, as shown in the following code:
using System;
using SQLite;
- Add the PrimaryKey and AutoIncrement attributes right before the ID property, as demonstrated in the following code:
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
The PrimaryKey attribute instructs SQLite that the Id property is the primary key of the table. The AutoIncrement attribute will make sure that the value of Id will be increased by one for each new TodoItem class that is added to the table.