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?

8
  • Why not trying System.Data.Sqlite available in nuget along with EntityFramework also in nuget? Commented Aug 17, 2015 at 15:20
  • System.Data.Sqlite is Windows-centric, it will not work on Linux or Mac or iOS or Android. Commented Aug 17, 2015 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. Commented Aug 17, 2015 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: github.com/oysteinkrog/SQLite.Net-PCL/blob/master/src/… @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 Commented Aug 17, 2015 at 16:08
  • SQLite-Net is cross-platform, System.Data.Sqlite is not. Commented Aug 17, 2015 at 16:15

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

2 Comments

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.
Can you tell what you installed / configured to get the CreateTable methods? I can't get it to work. (stackoverflow.com/questions/55949326/…)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.