4

我正在尝试使用 SQLite.net 在我的 PCL 中实现 OneToMany 关系。我有异步扩展包 (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
}
4

1 回答 1

6

使用时SQLiteAsyncConnection,您必须使用所有方法的异步 Nuget 包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必须等待或返回的 a。

于 2016-06-14T11:55:24.703 回答