// This method checks to see if the database exists, and if it doesn't, it creates // it and inserts some data. It also sets our database to be the default database // connection. protected void CheckAndCreateDatabase (string dbName) { // determine whether or not the database exists bool dbExists = File.Exists (GetDBPath (dbName)); // configure the current database, create if it doesn't exist, and then run the anonymous // delegate method after it's created CSConfig.SetDB (GetDBPath (dbName), SqliteOption.CreateIfNotExists, () => { CSDatabase.ExecuteNonQuery ("CREATE TABLE People (PersonID INTEGER PRIMARY KEY AUTOINCREMENT, FirstName text, LastName text)"); // if the database had to be created, let's populate with initial data if (!dbExists) { // declare vars CSList<Person> people = new CSList<Person> (); Person person; // create a list of people that we're going to insert person = new Person () { FirstName = "Peter", LastName = "Gabriel" }; people.Add (person); person = new Person () { FirstName = "Thom", LastName = "Yorke" }; people.Add (person); person = new Person () { FirstName = "J", LastName = "Spaceman" }; people.Add (person); person = new Person () { FirstName = "Benjamin", LastName = "Gibbard" }; people.Add (person); // save the people collection to the database people.Save (); } }); }