0

如何检索填充列表视图的 SQLite 条目的主键?我想检索突出显示的列表视图项的主键。entryList 是我的列表视图。

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.db");
    using (var db = new SQLiteConnection(dbPath))
    {
        db.CreateTable<Person>();

        db.RunInTransaction(() =>
        {
            db.Insert(new Person() { FirstName = "John", LastName = "Doe" });
        });
        entryList.ItemsSource = db.Table<Person>();
    }
}

public class Person
{
    [AutoIncrement,PrimaryKey]
    public int ID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

    public override string ToString()
    {
        return string.Format("{0}, {1}, {2}", LastName, FirstName, ID);
    }
}
4

0 回答 0