将SQLite表存储在ObservableCollection中?

时间:2018-01-29 21:56:03

标签: c# xamarin.forms sqlite.net

public ObservableCollection<AppUser> AppUser { get; set; }

public AppUserDbConnect(string dbPath)
{
    _database = new SQLiteAsyncConnection(dbPath);
    _database.CreateTableAsync<AppUser>().Wait();
    this.AppUser = new ObservableCollection<AppUser>(_database.Table<AppUser>());
}

此代码创建数据库连接,然后基于AppUser模型创建表。我试图存储最后一行的结果,但我面临以下错误:

  

CS1503参数1:无法转换   Dialler1.DatabaseConnection.AsyncTableQuery<AppUser>来   System.Collections.Generic.IEnumerable<AppUser>

1 个答案:

答案 0 :(得分:0)

db.Table<T>()

调用 ToList
 this.AppUser = new ObservableCollection<AppUser>(_database.Table<AppUser>().ToList());