【发布时间】:2016-09-16 14:10:22
【问题描述】:
我想将我的数据保存在 SQLite 数据库中,所以我安装了 SQLite.Net-PLC nuget 并在 android 和 iOS 中创建了一个连接,然后我安装了 SQLite.Net.Async-PLC nuget 和创建了一个存储库,我在其中定义了函数:插入、更新和删除,例如:
public Task<int> InsertAsync(T entity) {
return _connection.InsertAsync(entity);
}
我也创建这样的表:
public Repository(ISQLiteConnection connectionService) {
_connectionService = connectionService;
_connection = _connectionService.GetConnection();
_connection.CreateTableAsync<T>();
}
在我的页面中我想插入一个表格:
ISQLiteConnection connectionService = DependencyService.Get<ISQLiteConnection>();
var activityRepo = new Repository<Activity>(connectionService);
await activityRepo.InsertAsync(activity);
它给了我这个错误:SQLite.Net.SQLiteException: no such table: Activity
我放了一个断点,它正在创建表,并且在插入异步语句上弹出错误。
【问题讨论】:
-
表也是异步创建的。你有没有尝试等待它?可能还没有创建表。
-
我试图将创建表放在一个单独的函数中,然后使用 await 调用该函数,但它给了我这个错误:System.NotSupportedException:不了解 System.Collections.ObjectModel。 ObservableCollection`1[System.String]
标签: c# sqlite xamarin.forms