10

I am working on an WinRT app. I want to use sqlite-net-extensions to support OneToMany, ManyToMany.

using SQLiteNetExtensions.Attributes;
using SQLite;

[Table("WorkFlow")]
public class Workflow
{
    [PrimaryKey, AutoIncrement]
    public int WorkflowId { get; set; }
    public string Name { get; set; }
    public int Revision { get; set; }
    [OneToMany]
    public List<Step> Steps { get; set; }
}

[Table("Step")]
public class Step
{
    public string Type { get; set; }
    public string Description { get; set; }
    [ManyToOne]
    public Workflow Workflow { get; set; }
}

When I try to generate the tables for the database, it raises the exception:

An exception of type 'System.NotSupportedException' occurred in app_name.exe but was not handled in user code Additional information: Don't know about System.Collections.Generic.List`1 [app_name.Model.modelName]

This is coming from the SqlType in SQLite.cs.

But from the example on the sqlite-net-extensions homepage, List property should work fine.

This is a copy of their example:

public class Stock
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    [MaxLength(8)]
    public string Symbol { get; set; }

    [OneToMany]      // One to many relationship with Valuation
    public List<Valuation> Valuations { get; set; }
}

public class Valuation
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    [ForeignKey(typeof(Stock))]     // Specify the foreign key
    public int StockId { get; set; }
    public DateTime Time { get; set; }
    public decimal Price { get; set; }

    [ManyToOne]      // Many to one relationship with Stock
    public Stock Stock { get; set; }
}

Can anyone give me some suggestions to solve this problem? Thanks.

redent84
  • 18,901
  • 4
  • 62
  • 85
Brian Huang
  • 226
  • 2
  • 7
  • I'm having exactly the same issue, the [SQLite.cs](https://raw.githubusercontent.com/xamarin/xamarin-forms-samples/0b1a7966c12a7a2135632a79cbe5266db98c672c/Todo/SharedProject/Todo/Data/SQLite.cs) type parsing method: `string SqlType(TableMapping.Column p, bool storeDateTimeAsTicks)` has no interpretation of the List type so it throws the NotSupportedException. I tried using nuget and by adding the source (and its reference) of SQLiteNetExtensions without luck... Anybody? – Wizche Aug 26 '14 at 19:55
  • Did you find a solution? I'm stuck with the same issue – Pantelis Sep 13 '14 at 17:22
  • Nevermind, @redent84 gave the answer. – Pantelis Sep 13 '14 at 20:37

3 Answers3

9

This is usually an installation issue caused because SQLite-Net Extensions was compiled using a SQLite-Net library but you are running your App using another. You can try adding the PCL NuGet package to your project or you can download the sources from Git and reference the project directly.

redent84
  • 18,901
  • 4
  • 62
  • 85
  • What's a good way of determining whether I've got the right package(s) installed? I have the same problem as OP, still unresolved, and these are my installed SQLite packages: SQLite.Net.Core-PCL, SQLite.Net-PCL, SQLiteNetExtensions, sqlite-net-pcl, SQLitePCLRaw.bundle_green, SQLitePCLRaw.core, SQLitePCLRaw.lib.e_sqlite3.android, SQLitePCLRaw.provider.e_sqlite3.android, SQLitePCLRaw.provider.sqlite3.ios_unified. – Christofer Ohlsson Mar 19 '17 at 20:10
  • @ChristoferOhlsson 'sqlite-net-pcl' and 'SQLite.Net.Core-PCL' are conflicting packages. Make sure to use the latest alpha version of SQLite-Net Extensions and remove any other sqlite.net pcl reference – redent84 Mar 20 '17 at 11:52
  • Thank you! I'll be trying to get that to work now. I had thought that maybe something like that was going on, but when Iooked at SQLite-Net-PCL I noticed it listed SQLite.Net.Core-PCL as a dependency. That doesn't sound like they should be in conflict? – Christofer Ohlsson Mar 20 '17 at 14:45
  • Okay, so I removed all the packages I mentioned above, and then re-installed SQLiteNetExtensions (and it added the two packages mentioned first). But now my DbConnection constructor does not accept one parameter, so I guess I need some of those other packages too. Should I ínstall all of them, except for the one called "sqlite-net-pcl"? – Christofer Ohlsson Mar 20 '17 at 15:15
3

Try giving Table (Step) a Primary Key and a Foreign Key referencing Table (WorkFlow)

[Table("Step")]
public class Step
{
    [PrimaryKey, AutoIncrement]
    public int StepId { get; set; }
    [ForeignKey(typeof(WorkFlow))]
    public int WorkFlowId { get; set; }
    public string Type { get; set; }
    public string Description { get; set; }
    [ManyToOne]
    public Workflow Workflow { get; set; }
}
MJ33
  • 859
  • 12
  • 25
0

Fix: Uninstall all references to any SQLite NuGet packages from all projects, in my case this was a Xamarin.Forms solution. Clean the solution as an extra precaution (you could even check the packages are uninstalled from the packages folder just in case there's a file access issue blocking the delete). Install again by searching for SQLiteNetExtensions (not sqlite-net-pcl) and checking that the 'Include prerelease' option is selected in Visual Studio (tested on 2017). This will install sqlite-net-pcl v1.2.0 as the minimum dependency and several files including the word 'Raw'. You can test at this point to check the 'Don't know about System.Collections.Generic.List`1' error. For me, this disappeared. It should now be safe to update sqlite-net-pcl to the latest version, which at time of writing is v1.3.3.

Background: I encountered the same issue with the following combination:

  1. sqlite-net-pcl v1.3.3
  2. SQLiteNetExtensions v2.0.0-alpha2

In my first attempt I installed sqlite-net-pcl first through NuGet and then installed the latest stable version of SQLiteNetExtensions. After discovering the extensions are not compatible with sqlite-net-pcl I then updated to the latest pre-release version. I encountered the same 'Don't know about System.Collections.Generic.List`1' bug and found it very confusing leading me to try other things first and question if I'd made a mistake. Cleaning the project, deleting the packages (from the folder) and restoring did not work for me. I didn't check the packages config but using the NuGet manager and comparing to a test project everything was the same. Uninstalling everything as mentioned in my fix and letting SQLiteNetExtensions do the dependency checking for me fixed the problem. I think there was a problem buried in the NuGet files from having the wrong version of SQLiteNetExtensions initially.

P.S. Earlier in the day NuGet downloaded two packages for a fresh Xamarin.Forms project with 0KB file size that was installed in a typical way and I had to copy them in from another project. I don't normally get NuGet related issues.

Michael
  • 31
  • 1