Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SQLite-Net Extensions and SQLiteConnection in Xamarin.Mac

I'd like to know, how can I use SQLite-Net Extensions within Xamarin.Mac project?

I'm using Xamarin Studio 5.9.5, I've created project from Mac->App->Empty project (Unified API). Installed package SQLite-Net Extensions. Here is the beginning of my code:

        var db = new SQLiteConnection(???????, dbPath);
        db.CreateTable<Stock>();
        db.CreateTable<Valuation>();

How can I call SQLiteConnection constructor? I need sqlite platform as first parameter, but there are no SQLite.Net.Platform. dlls added to references.

This answer is not helpful, because there are no such dlls/namespaces (SQLite.Net.Platform). Also I can't find this package - SQLite.Net.Platform.XamarinIOS.

I want to use SQLite-Net Extensions because of its one-to-one, one-to-many.. relationships. My question is How can I create instance of SQLiteConnection?

Why there is no SQLite.Net.Platform.Generic or SQLite.Net.Platform.Win32 dlls in references from that package?

like image 557
voytek Avatar asked Aug 17 '15 15:08

voytek


1 Answers

The problem was in project type I choose. I choose Empty project that targets the new Unified API. For that project SQLiteNetExtensions package doesn’t have required libraries, such as SQLite.Net.Platform.Generic.

To solve that problem you could either choose project that targets Classic API (for that project SQLiteNetExtensions contains SQLite.Net.Platform) or create Unified API project and after adding SQLiteNetExtensions package, manually add SQLite.Net.Platform dlls to references.

Although, I'm not sure why these .Platform libraries are included in SQLiteNetExtensions package for Classic API and not for Unified API

This is how it works in my project:

dbConnection = new SQLiteConnection(new SQLite.Net.Platform.Generic.SQLitePlatformGeneric(), databasePath);
like image 115
voytek Avatar answered Sep 19 '22 19:09

voytek