我正在尝试使用SQLite.net在我的PCL中实现OneToMany关系。我有async扩展包(SQLiteNetExtensions.Async),我的代码基于https://bitbucket.org/twincoders/sqlite-net-extensions中的示例。我使用的是SQLiteAsyncConnection,但UpdateWithChildren方法似乎不可用,只能使用SQLiteConnection。
using SQLite.Net;
using SQLite.Net.Async;
using SQLite.Net.Interop;
using SQLiteNetExtensions.Extensions;
private readonly SQLiteAsyncConnection conn;
public ActivityRepository(ISQLitePlatform platform, string dbPath)
{
var connectionFactory = new Func<SQLiteConnectionWithLock>(() => new SQLiteConnectionWithLock(platform, new SQLiteConnectionString(dbPath, storeDateTimeAsTicks: true)));
conn = new SQLiteAsyncConnection(connectionFactory);
}
public void method(object object) {
conn.UpdateWithChildren(object); --function not available
}
答案 0 :(得分:3)
使用SQLiteAsyncConnection
时,您必须使用async Nuget package,SQLiteNetExtensionsAsync.Extensions
命名空间和所有方法的异步版本:
using SQLite.Net;
using SQLite.Net.Async;
using SQLite.Net.Interop;
using SQLiteNetExtensionsAsync.Extensions;
private readonly SQLiteAsyncConnection conn;
public ActivityRepository(ISQLitePlatform platform, string dbPath)
{
var connectionFactory = new Func<SQLiteConnectionWithLock>(() => new SQLiteConnectionWithLock(platform, new SQLiteConnectionString(dbPath, storeDateTimeAsTicks: true)));
conn = new SQLiteAsyncConnection(connectionFactory);
}
public Task method(object object) {
return conn.UpdateWithChildrenAsync(object);
}
请注意,所有异步方法都会返回必须等待或返回的Task
。