使用SQLite.Net.Async的Xamarin.Forms [英] Xamarin.Forms using SQLite.Net.Async

查看:45
本文介绍了使用SQLite.Net.Async的Xamarin.Forms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照此处的说明 http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/databases/-同步连接到SQLite数据库.

I have followed the instructions here http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/databases/ - to connect to the SQLite database synchronously.

public SQLiteConnection GetConnection()
{
    var dbFilname = "localDB.db3";
    string docsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
    var path = Path.Combine(docsPath, dbFilname);

    var plat = new SQLitePlatformAndroid();
    var conn = new SQLiteConnection(plat, path);
    return conn;
}

我想将其更改为异步连接(SQLiteAsyncConnection),但无法使其正常工作.

I want to change it to an asynchronous connection (SQLiteAsyncConnection) but can't get it to work.

根据此处的说明- https://components.xamarin.com/gettingstarted/sqlite-net -它只需要将路径作为参数

According to the instructions here - https://components.xamarin.com/gettingstarted/sqlite-net -it just needs the path as a parameter

var conn = new SQLiteAsyncConnection(path);

不起作用,错误提示期望的参数是:

that doesn't work, the error says that the parameters expected are:

连接功能,TaskScheduler和TaskCreationOptions

a connection function, a TaskScheduler and TaskCreationOptions

我不知道该怎么办,也找不到任何可行的例子.

I have no idea what to do and have not been able to find any examples that work.

预先感谢

推荐答案

您可以简单地重用已有的GetConnection方法并创建异步连接,如下所示:

You could simply reuse the GetConnection method you already have and create async connection like this:

var asyncDb = new SQLiteAsyncConnection(() => GetConnection());

这篇关于使用SQLite.Net.Async的Xamarin.Forms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆