I have a CodePlex project for Isolated Storage based database for Windows phone 7. You can check out this project at http://winphone7db.codeplex.com/
First step is to download the project and build it on your copter. Visit the download page for the latest recommended download. Unzip the source code on your machine, open it up in Visual Studio 2010 and compile to create a DLL.
Next, create new Windows Phone 7 project and add a reference to the DLL from step 1.
Next, in your View Model (or elsewhere in your application) check for database existence and create if it does not exist along with tables. See sample code below
if (!Database.DoesDatabaseExists(DatabaseName))
{
database = Database.CreateDatabase(DatabaseName);
database.CreateTable<Person>();
database.CreateTable<PersonDetail>();
database.Save();
}
else
{
database = Database.OpenDatabase(DatabaseName, string.Empty, true);
}
In the sample above I am testing if database exists, then create it if it does not, Then I am adding two tables to it based on POCO classes. For example, Person class would look like
public class Person
{
public Guid PersonID { get; set; }
public string FirstName { get; set; }
public string LasstName { get; set; }
}
If you would like to add a row to a table, just issue Add command:
db.Table<Person>().Add(NewPerson());
New Person routine just returns Person instance.
To remove, just issue remove command:
db.Table<Person>().Remove(person2);
You can also remove and add a range of items based on condition.
db.Table<Person>().RemoveRange((person) => { return (person.Salary >= 2); });
You can also add a range of items, specifically IEnumerable<T>
db.Table<Person>().AddRange(list);
Make sure to call Save() on either database or a specific table to commit your changes.
You can also look in unit test project that is distributed as part of the source code download for other API samples.