c# - SQLite 的 VS 项目/解决方案结构

标签 c# sqlite windows-phone-8 portable-class-library

我正在使用 VS2013 开发一个项目,该项目将面向 x86 或 x64 架构上的 WP8、WinRT 和 Windows 桌面平台。

这个项目需要本地数据访问/存储,我选择了 SQLite。

我想知道是否有人可以向我指出资源/博客/示例,这些资源/博客/示例将向我展示如何创建一个数据层,该数据层将允许我针对上述所有内容,同时仍然尽可能多地为我的公共(public)代码库保留数据层?

我有每个 SQLite“风格”的 vsix 扩展,还有 C# 包装器 System.Data.SQLite

非常感谢,

理查德

最佳答案

您将必须创建一个可供所有这些平台使用的可移植类库。

在该可移植类库中,您将需要使用一个接口(interface),并且必须传入特定于平台的实现(WP8 和 WindowsRT 需要的实现略有不同)。

但这对我有帮助。可能还有一些其他资源,但这绝对是最好的,也是让我能够完全按照您的意愿去做的资源。

这是我关注的系列(并在此过程中进行了一些更改),但它对我帮助很大。 http://nicksnettravels.builttoroam.com/post/2013/06/02/Windows-(RT-and-Phone)-and-Sqlite-(Part-1).aspx

以下是本系列第 4 部分的一些片段:

create a separate SQLitePCL project and to define a set of interfaces which map to the classes/methods which is exposed by Sqlite-net. I’m not going to bore you with the details but you can see from following image just a couple of the interfaces which will map to classes such as the SQliteConnection, TableMapping and Column.

关于平台实现:

For each platform we need to implement these interfaces. This is really a matter of taking the sqlite-net classes, defined in SQLite.cs and SQliteAsync.cs and modifying them to implement the defined interfaces. This isn’t quite as simple as adjusting the class signature to include the appropriate interface but it isn’t far off.

We need to create a separate class library for each platform, eg SQLiteWinRT and SQLiteWP8. It doesn’t matter which platform you start with (I did the phone implementation first) since you’ll be referencing the same classes using the “add as link” technique discussed in the previous post. You might be thinking, if we’re simply going to be adding the same classes to both libraries why they can’t be all in the shared PCL. The answer lies in the conditional compilation statements at the top of the sqlite-net files – these determine how the classes are built for the respective platforms.

关于c# - SQLite 的 VS 项目/解决方案结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20704077/

相关文章:

c# - .NET core WebAPI POST 中的奇怪主体。序列化不正确?

c# - 从 NodeJS 验证 "Owin OAuth Bearer Token"

c# - “短工具”Getter 'Long-Implement' Setter

select - 选择后触发

angularjs - Azure AD 应用程序、cordova、adal-Angular、Windows Phone 8 重定向 url

c# - LINQ 查询中的错误

Python - 如何将 SQLAlchemy 连接到内存中的现有数据库

vb.net - 一次性类引用

windows - 如何将 Windows Phone Emulator only Emulator 7 升级到 Emulator 8

c# - 为 Windows Phone 8 创建两列、垂直堆叠的列控件