SQLite.net extensions in a shared project

Ive searched pretty extensively and come across some posts which do not seem to address what I am experiencing but I'll try to step through what I have encountered.

I have a Xamarin forms app using shared code and at the time was using the raw source code for SQLite.net as recommended for a shared code project in the Xamarin docs. I am using SQLite.Net without issue and wanted to add in the sqlite extensions to use some of it's features. Initially I an into the problems I've seen in other posts where there is a conflict between using the sqlite.net code and the nuget package for the extensions. I would get errors with respect to SQLite.net not dealing with generic lists. Following some other recommendations I deleted the raw sqlite.cs file and installed the sqlite-net-extensions nuget package and it brought in the version of SQLite.net it needed. I was concerned because it was described as being PCL and I wasn't sure if it would work in a shared project.

Now I see that all the references to sqlite.* need to be changed to sqlite.net.* so I set up a simple test project and for the life of me I can't get anything to compile. To get a connection to the SQLite db before I included the extensions I used:

var conn = new SQLite.SQLiteConnection(path);

For the path I would get a platform specific path. Not the new package int the SQLite.Net.SQLiteconnection constructor it wants an additional platform parameter which I can find no example on how to use. I have also tried setting it up as recommend for PCL app using the dependency resolver. That also fails for the same missing parameter reason.

In short, is there a way to use the sqlite-net extensions in a xamarin forms shared app?

These are some of the posts I came across which don't appear to apply to my current errors:

https://forums.xamarin.com/discussion/20117/sqlite-net-extensions-and-sqliteconnection

https://forums.xamarin.com/discussion/20385/sqlite-extension-with-shared-project

Posts

  • BrianAllenBrianAllen USMember

    I ended up including the source for both sqlite.cs and the files for sqlite-net extensions and built them within my project and got it working.

    I did have to change some of the code in the extensions library to get it to compile. Not sure if this is a bug but if you are not using the MVVMCross there are 3 methods with generic constraints that create errors on build. For the define USING_MVVMCROSS it constrains the type to 'new()' but else it then constrains to 'class'. I had to change both to 'new()' because the calls into sqlite.cs require a parameterless constructor.

Sign In or Register to comment.