10

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?

Community
  • 1
  • 1
voytek
  • 2,202
  • 3
  • 28
  • 44
  • Why not trying `System.Data.Sqlite` available in `nuget` along with `EntityFramework` also in `nuget`? – Clive DM Aug 17 '15 at 15:20
  • System.Data.Sqlite is Windows-centric, it will not work on Linux or Mac or iOS or Android. – jstedfast Aug 17 '15 at 15:46
  • @voytek Why not use the .ctor that does not take a platform argument? That argument must be new because I've used SQLite-Net for years and never saw that argument, I've always just passed in a path. – jstedfast Aug 17 '15 at 15:47
  • @jstedfast what do you mean, it will not work on Mac? I thought, It's a cross-platform lib. `SQLite-Net Extensions` works with `SQLite-Net PCL` which doesn't have one-param constructor:/ look here: https://github.com/oysteinkrog/SQLite.Net-PCL/blob/master/src/SQLite.Net/SQLiteConnection.cs#L102 @CliveDM I wanted to use extension package cause it's all in one. Code looks very clean. If it's not possible I will have to look for other solutions – voytek Aug 17 '15 at 16:08
  • SQLite-Net is cross-platform, System.Data.Sqlite is *not*. – jstedfast Aug 17 '15 at 16:15
  • ahh sorry. You were answering Clive, I misread and thought you answering me – voytek Aug 17 '15 at 16:27
  • @clive DM, I don't think anyone has ported the Microsoft Entity framework to Xamarin.iOS / Xamarin.Mac. I know there are issues with Xamarin.Ios as there are limitations with reflection at run-time as there is no runtime compilation. Anyway SQLite.Net is a great light weight orm and there are lots of reasons to use it in preference. – AnthonyLambert Aug 17 '15 at 16:48
  • if you find an earlier version of SQLite.Net it was implemented as a single .cs file that you could just include in your project. When they tidied it up they split it into lots of files with projects to build each target etc... which ironically may make your life more difficult. see https://github.com/praeclarum/sqlite-net/tree/master/src – AnthonyLambert Aug 17 '15 at 16:52

1 Answers1

8

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);
voytek
  • 2,202
  • 3
  • 28
  • 44
  • 1
    omg you are my hero. I have been beating my head against the wall for longer than I'm willing to admit, trying to get SQLite.NET PCL to play nice with a Xamarin.Mac project. Your answer lead me to a solution. I manually added a reference to the Sqlite.Net.Platform.Generic.dll to my PCL project. I don't like this solution, but I don't care at this point, it works. – user2051770 Oct 20 '15 at 16:25
  • Can you tell what you installed / configured to get the CreateTable methods? I can't get it to work. (https://stackoverflow.com/questions/55949326/missing-createtable-and-table-methods-in-sqlite-sqliteconnection-class) – marsh-wiggle May 02 '19 at 12:17