Xamarin.form上的SQLite数据库访问

时间:2017-04-12 04:55:26

标签: database sqlite xamarin

我是SQLite的新手,我正在尝试从SQLite数据库中获取字符串。但我无法返回people.Name,因为人们是AsyncTableQuery。有什么想法吗?

这是代码:

readonly SQLiteAsyncConnection _database;

public string GetNameByID(int id)
{
    var people = from t in _database.Table<Model>() where t.ID == id select t;

    return people.Name;
}

1 个答案:

答案 0 :(得分:1)

定义AsyncTableQuery后,您可以通过List

将其转到ToListAsync

示例:

var people = from t in _database.Table<Model>() where t.ID == id select t;
await people.ToListAsync();
foreach (var person in people)
{
    Debug.WriteLine(person.Name);
}