简体   繁体   English

Xamarin.Forms 中的 SQLite-Net-Pcl

[英]SQLite-Net-Pcl in Xamarin.Forms

I am trying to learn SQLite and its usage from Xamarin.Forms.我正在尝试从 Xamarin.Forms 学习 SQLite 及其用法。 I found that it is recommended to install Sqlite-net-pcl as NuGet package and make use of it to create, open, modify a database.我发现推荐安装 Sqlite-net-pcl 为 NuGet package 并使用它来创建、打开、修改数据库。 Up to that point everything is fine.到那时一切都很好。 However, I am struggling to find more details about Sqlite-net-pcl on the web.但是,我很难在 web 上找到有关 Sqlite-net-pcl 的更多详细信息。 It seems, a comprehensive documentation is not available for this library.看来,该库没有全面的文档。 And this reality brought some questions to my mind which I believe I could get answer from Stackoverflow seniors:这个现实让我想到了一些问题,我相信我可以从 Stackoverflow 的前辈那里得到答案:

1-If there is no documentation of a library which you are trying to use, what is the best way to learn it quickly? 1-如果没有您尝试使用的库的文档,那么快速学习它的最佳方法是什么? Trial&Error?试错? In that case full class hierarchy would be needed, I think.在这种情况下,我认为需要完整的 class 层次结构。 2-As I understood, Sqlite-net-pcl is a partial implementation of Sqlite. 2-据我了解,Sqlite-net-pcl 是 Sqlite 的部分实现。 For instance, in the documentation of Sqlite, it is said, Foreign key is supported but should be enabled.例如,在 Sqlite 的文档中,说支持外键,但应该启用。 But, I couldnt find this attribute in Sqlite-net-Pcl when I used the ObjectBrowser tool of VisualStudio.但是,当我使用 VisualStudio 的 ObjectBrowser 工具时,我在 Sqlite-net-Pcl 中找不到这个属性。
3-Considering, SQLite have better support, If I want to use SQLite directly in xamarin.forms(c#) instead of its derived versions(Sqlite-net-pcl) how can I achieve this? 3-考虑到,SQLite 有更好的支持,如果我想直接在 xamarin.forms(c#) 中使用 SQLite 而不是其派生版本(Sqlite-net-pcl),我该如何实现?

It is preferable to use SQLite-net libraries.最好使用 SQLite-net 库。 They are simply a wrapper around SQLite flow.它们只是 SQLite 流的包装。 You have everything that you need there.你有你需要的一切。 Also, if you want to use an ORM, you can also use EntityFrameworkCore via Microsoft.EntityFrameworkCore.Sqlite此外,如果您想使用 ORM,您还可以通过Microsoft.EntityFrameworkCore.Sqlite使用 EntityFrameworkCore

Like it is said in the GitHub repository :就像GitHub 存储库中所说的那样:

SQLite-net is an open source, minimal library to allow .NET, .NET Core, and Mono applications to store data in SQLite 3 databases. SQLite-net 是一个开源的最小库,允许 .NET、.NET Core 和 Mono 应用程序将数据存储在 Z497757A9C5B2EC178ED8 数据库中。 It was first designed to work with Xamarin.iOS, but has since grown up to work on all the platforms (Xamarin.*, .NET, UWP, Azure, etc.). It was first designed to work with Xamarin.iOS, but has since grown up to work on all the platforms (Xamarin.*, .NET, UWP, Azure, etc.).

About the Foreign Key - there isn't any constraints.关于外键 - 没有任何限制。 You can use it freely without any "enabling".您可以自由使用它而无需任何“启用”。

There are some other options like Microsoft.Data.SQLite & System.Data.SQLite , but I haven't tried them with Xamarin and, if they work, I don't think that they will have better support for Mono, like the one that you have with SQLite-net. There are some other options like Microsoft.Data.SQLite & System.Data.SQLite , but I haven't tried them with Xamarin and, if they work, I don't think that they will have better support for Mono, like the one您使用 SQLite-net 所拥有的。 The latter is also updated constantly.后者也在不断更新。

Here is the official tutorial from Microsoft about using sqlite-net-pcl 是微软关于使用 sqlite-net-pcl 的官方教程

If you want to use an ORM, you can follow this article from the official docs on how to setup the SQLite libraries, together with EFCore packages, migrations, etc.如果您想使用 ORM,您可以按照官方文档中的这篇文章了解如何设置 SQLite 库,以及 EFCore 包、迁移等。

Should you choose to use EFCore, please consider the Migration Limitations .如果您选择使用 EFCore,请考虑迁移限制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM