从sqlite条目中检索主键

时间:2012-08-14 22:30:08

标签: c# sqlite windows-8 microsoft-metro

如何检索填充列表视图的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);
    }
}

0 个答案:

没有答案