Ever since Xamarin 3 came out, several of us have been looking at ways to streamline the somewhat-painful task of writing apps for multiple platforms. Sure, Xamarin makes it so you can write C# code and deploy to Win8, WP8, iOS, Android, etc – but the “devil is in the details”. What about a database? How do you manage settings? How do you sync things perhaps to the user’s cloud storage? How do you do that across different devices!?
Well, in exploring that, I came up with some useful code which I intend to build on. What it is right now though, is an ORM (read: Entity Framework-like) Repository pattern on top of SQLite. If you are not aware, SQLite is one of the few database formats which works on ALL of the Xamarin platforms.
There is some MVVM-friendly functionality too. The best part is this is a Portable Class Library (PCL), meaning that it is framework-agnostic. This “database layer” code works for all Visual Studio/Xamarin platforms including iOS and Android, in addition to all the Microsoft platforms too.
It’s ONE solution for an app database for: WIndows Store, Windows Phone, iPad, iPhone, and Android.
The intent here is to make it so you can just add this NuGet package to your project and you’d instantly have SQLite repositories, with MVVM/XAML-friendly ViewModels with just a few lines of code.
This project is open-source and is available here (with GPLv3 license):
As of this writing, this has 90.9% unit test code coverage, and is pretty fully documented with XML code comments. Actual example code and more developer documentation is forthcoming.
This project is also published in NuGet and is available here:
Or of course you can install from the Package Manager Console in Visual Studio:
or by right-clicking on a project and choosing Manage NuGet Packages:
Some of the next things to be considered are ways to sync data to various cloud providers. For example, imagine you add a record in your app on your local phone. Wouldn’t it be ideal to sync that change to the persons DropBox, GoogleDrive, OneDrive, Copy, etc so that if you then picked up your iPad or launched your Windows Store app, you’d see that change too.
If you have any questions, comments, or issues – please let me know.