2

I am trying to learn SQLite and its usage from Xamarin.Forms. 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. Up to that point everything is fine. However, I am struggling to find more details about Sqlite-net-pcl on the web. 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:

1-If there is no documentation of a library which you are trying to use, what is the best way to learn it quickly? Trial&Error? In that case full class hierarchy would be needed, I think. 2-As I understood, Sqlite-net-pcl is a partial implementation of Sqlite. For instance, in the documentation of Sqlite, it is said, Foreign key is supported but should be enabled. But, I couldnt find this attribute in Sqlite-net-Pcl when I used the ObjectBrowser tool of VisualStudio.
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?

TiTus
  • 77
  • 9

1 Answers1

3

It is preferable to use SQLite-net libraries. They are simply a wrapper around SQLite flow. You have everything that you need there. Also, if you want to use an ORM, you can also use EntityFrameworkCore via Microsoft.EntityFrameworkCore.Sqlite

Like it is said in the GitHub repository:

SQLite-net is an open source, minimal library to allow .NET, .NET Core, and Mono applications to store data in SQLite 3 databases. 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. The latter is also updated constantly.

Here is the official tutorial from Microsoft about using 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.

Should you choose to use EFCore, please consider the Migration Limitations.

Mihail Duchev
  • 4,691
  • 10
  • 25
  • 32
  • Thanks for the reply. But, SQLite-net-pcl official tutorial, shows only 5-6 method of sqlite-net. Actually, it seems quite easy if this tutorial includes complete set of functionalities. I believe there is more! How can I reach and check them? – TiTus May 05 '20 at 17:47
  • I don't believe there is such tutorial to include all of the methods available. You can either check the documentation here: https://github.com/praeclarum/sqlite-net/wiki or simply use Entity Framework, where you have all the documentation in the world. Also, you can browse the GitHub code or just install the library and see which methods are available. You can write your own custom queries, so if something isn't exposed, you can always write the sql query by hand and do what you meant to. – Mihail Duchev May 05 '20 at 17:53
  • The only place that I didn't checked was the code page at github. It shows all source code! Thanks. – TiTus May 07 '20 at 00:56
  • Actually Microsoft.Data.SQLite seems to have better support for me on iOS than SQLite when accessing db’s in UIDocument public folders that I created. SQLite is giving me access denied on a db I created, so I’m trying to figure out how to get around it. – John Ernest Jan 02 '21 at 00:54