I am using Vici.CoolStorage in a Windows Phone 7 application to access a SQLite database. I am getting a Null Reference Exception on this line:
CSList<Regimen> regimens = Regimen.List();
I have two tables in my database:
CREATE TABLE Regimen (
ID INTEGER PRIMARY KEY,
Name TEXT(50) NOT NULL
);
CREATE TABLE WorkoutDay (
ID INTEGER PRIMARY KEY,
DayNumber INTEGER NOT NULL,
RegimenID INTEGER REFERENCES Regimen(ID)
);
The Mapping for the related models is:
using Vici.CoolStorage;
namespace MyApp.Core.Domain
{
[MapTo("Regimen")]
public class Regimen : CSObject<Regimen,int>
{
public int ID
{
get { return (int)GetField("ID"); }
set { SetField("ID", value); }
}
public string Name
{
get { return (string)GetField("Name"); }
set { SetField("Name", value); }
}
[OneToMany(LocalKey = "ID", ForeignKey = "RegimenID")]
public CSList WorkoutDays
{
get { return (CSList)GetField("WorkoutDays"); }
}
}
}
using Vici.CoolStorage;
namespace MyApp.Core.Domain
{
[MapTo("WorkoutDay")]
public class WorkoutDay : CSObject<WorkoutDay,int>
{
public int ID
{
get { return (int)GetField("ID"); }
set { SetField("ID", value); }
}
public int DayNumber
{
get { return (int)GetField("DayNumber"); }
set { SetField("DayNumber", value); }
}
[ManyToOne(LocalKey="RegimenID", ForeignKey="ID")]
public Regimen Regimen
{
get { return (Regimen)GetField("Regimen"); }
set { SetField("Regimen", value);}
}
}
}
If I comment out the OneToMany relationship in the Regimen model, it works fine. I can't figure out what's wrong with my mapping.