如何从 SQLite 的异步 PCL 版本使用 SQLiteAsyncConnection? [英] How to use SQLiteAsyncConnection from the async PCL version of SQLite?
问题描述
我正在使用来自 https://github.com/的 Sqlite.net 的 PCL 版本oysteinkrog/SQLite.Net-PCL
但是,我无法进行数据库连接设置.SQliteAsyncConnection
与原始版本不同,它不采用字符串(数据库的路径),而是采用 [Func<;SQLiteConnectionWithLock>.]
2
However, I'm unable to get the DB connection setup. The SQliteAsyncConnection
does unlike the original version not take a string (path to the DB), but a [Func< SQLiteConnectionWithLock>.]
2
这个怎么用?一般来说:如何使用这个库?我有一个核心 PCL 库,它执行我的 iOS、Android 和 WP8 项目的所有业务逻辑.我的理解是我可以将 Sqlite-Net Async PCL 放入我的 PCL 库中.但似乎我必须提供一些特定于平台的东西才能让它工作.
How can this be used? In general: how to use this library? I have a core PCL lib which does all the business logic from my iOS, Android and WP8 projects. My understanding was that I can drop the the Sqlite-Net Async PCL into my PCL lib. But it seems like I have to provide some platform specific stuff to get it to work.
推荐答案
您只需要创建一个返回 SQLiteConnectionWithLock
的函数,并将其传递给 SQLiteAsyncConnection
构造函数.
You just need to create a function that returns a SQLiteConnectionWithLock
and pass that to the SQLiteAsyncConnection
constructor.
string databasePath = "path";
var connectionFactory = new Func<SQLiteConnectionWithLock>(()=>new SQLiteConnectionWithLock(new SQLitePlatformWinRT(), new SQLiteConnectionString(databasePath, storeDateTimeAsTicks: false)));
var asyncConnection = new SQLiteAsyncConnection(connectionFactory);
这篇关于如何从 SQLite 的异步 PCL 版本使用 SQLiteAsyncConnection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!