I am writing a Xamarin Android application using SQLite and am not sure how to add an object to a table where the object has a list.
Here is my model class:
public class TestObject
{
[PrimaryKey]
public int Id { get; set; }
public string name { get; set; }
public DateTime lastUpdate { get; set; }
public List<TestItem> items { get; set; }
}
Here is my code to add an object to a table:
public void InsertObjectToDatabase<T>(string databasePath, T objType)
{
var db = new SQLiteConnection (databasePath);
db.CreateTable(typeof (T));
db.InsertOrReplace (objType);
}
Here is my code to add a TestObject to a table:
TestObject testObject = new TestObject ();
testObject.Id = 1;
testObject.name = "Test Object 1";
testObject.lastUpdate = DateTime.Now;
sQLiteService.InsertObjectToDatabase<TestObject> (filename, testObject);
This is the error that I am getting:
System.NotSupportedException: Don't know about System.Collections.Generic.List`1[LearningSQLite.TestItem]
Is it possible add a list to a SQLite table?
Thanks in advance