【问题标题】:How to use the SQLite in xamarin.forms windows phone 8 project?如何在 xamarin.forms windows phone 8 项目中使用 SQLite?
【发布时间】:2016-07-23 20:35:27
【问题描述】:

我创建了一个包含 Android、iOS 和 Windows Phone 的 Xamarin.Forms 项目。我正在尝试在 Xamarin Windows Phone 8.1 项目中使用 Sqlite 数据库,并且我已经安装了 sqlite.net pcl 以及带有平台库的核心和异步库。当我尝试运行该项目时,它显示错误 winrt.dll sqlite3 找不到。 sqlite.platforms.windowsPhone8 实际上有两个参考库,所以我将它添加为 x86 但仍然有问题。 这是我的 windows phone 8.1 代码

    namespace SwachhParyatanApp.WinPhone
{
    class DBPath_WinPhone : IDBPath
    {
        public SQLiteAsyncConnection GetDBPath()
        {
            var path = Path.Combine(ApplicationData.Current.LocalFolder.Path, "localData.db");
            var platform = new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT();
            var param = new SQLiteConnectionString(path, false);
            var connection = new SQLiteAsyncConnection(() => new SQLiteConnectionWithLock(platform, param));
            return connection;
        }
    }
}

每当我尝试使用依赖服务调用时,它都会在 var platform = new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(); 行上显示错误;

默认情况下,WinRT 库已添加到项目中,但它也有问题,因此我添加了 windowsphone8 库。

【问题讨论】:

    标签: sqlite windows-phone-8.1 xamarin.forms sqlite.net


    【解决方案1】:

    我找到了答案,我们需要从 sqlite.org 手动为 windows phone 8.1 WinRT 站点添加 sqlite3.dll。

    【讨论】:

      【解决方案2】:

      Windows 手机不包括 SQLite,如 iOS 和 Android。

      你需要为VS下载SQLite extension,并在你的项目中引用它。

      我建议使用SQLite-net PCL,它是 SQLite 的 ORM,并在常规 SQLite API 之上提供了不错的异步/同步 API

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-11-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多