【问题标题】:SQLiteAsyncConnection UpdateWithChildren not availableSQLiteAsyncConnection UpdateWithChildren 不可用
【发布时间】:2016-06-14 19:55:24
【问题描述】:

我正在尝试使用 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
}

【问题讨论】:

    标签: xamarin sqlite-net-extensions


    【解决方案1】:

    使用SQLiteAsyncConnection时,必须使用async Nuget packageSQLiteNetExtensionsAsync.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

    【讨论】:

    • 谢谢,我安装了异步包,只是没有使用 UpdateWithChildrenAsync 方法。
    猜你喜欢
    • 1970-01-01
    • 2016-06-10
    • 2020-05-20
    • 1970-01-01
    • 2018-04-17
    • 2018-03-07
    • 1970-01-01
    • 2018-07-23
    • 1970-01-01
    相关资源
    最近更新 更多