I'm implementing SQLite database in my Windows Store application (WinRT). I want to relation between two tables (1:n) Book (1) - Chapter (n)
class Book
{
[SQLite.AutoIncrement, SQLite.PrimaryKey]
public int Id { get; set; }
public String Title { get; set; }
public String Description { get; set; }
public String Author { get; set; }
public List<Chapter> Chapters { get; set; }
public Book()
{
this.Chapeters = new List<Chapter>();
}
}
I get
- $exception {"Don't know about System.Collections.Generic.List`1[Audioteka.Models.Chapter]"} System.Exception {System.NotSupportedException}
+ [System.NotSupportedException] {"Don't know about System.Collections.Generic.List`1[Audioteka.Models.Chapter]"} System.NotSupportedException
+ Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
HelpLink null string
HResult -2146233067 int
+ InnerException null System.Exception
Message "Don't know about System.Collections.Generic.List`1[Audioteka.Models.Chapter]" string
What am I doing wrong ?
Take a look at SQLite-Net Extensions. It provides complex relationships on top of SQLite-Net by using reflection.
Example extracted from the site:
Just to follow up on my comment with a bit more research - SQLite-net doesn't support anything which can't be directly mapped to the database. See here for why:
You can look into using a different ORM to actually access your data (I use Vici Coolstorage), if that's what you're trying to do, or simply remove the
List<Chapters>
from your class and add aBookID
field to theChapters
class. That's how the database would represent it.For purposes of working with it, you could add one of these to your class:
or
That would at least let you pull the list easily, although it would be slow because it hits the database every time you access it.