http://rongchaua.net/blog/windows-phone-7-simple-database-example/
Today when I start to play around with developing on Windows Phone 7, I would like to write a first small database application because Windows Phone does not support SQL Server any more. Therefore I must use either LINQ over XML or store the database somewhere on server/Windows Azure and provide services so that the client can access and make query to get and update data. In this small example, I would like to work with LINQ To XML to create a database and update it.
My data object (data entity) is a class of Student with his first name, last name and email built by appending first name and last name as describing below
view source
print?
01
publicclass Student
02
{
03
publicstring EMail { get; set; }
04
publicstring FirstName { get; set; }
05
publicstring LastName { get; set; }
06
07
public Student(string FirstName, string LastName)
08
{
09
this.FirstName = FirstName;
10
this.LastName = LastName;
11
EMail = FirstName + "@" + LastName + ".com";
12
}
13
14
public Student(XElement xElement)
15
{
16
EMail = xElement.Attribute("EMail").Value;
17
FirstName = xElement.Element("FirstName").Value;
18
LastName = xElement.Element("LastName").Value;
19
}
20
21
public XElement Information
22
{
23
get
24
{
25
returnnew XElement("Student",
26
new XAttribute("EMail", EMail),
27
new XElement("FirstName", FirstName),
28
new XElement("LastName", LastName));
29
}
30
}
31
}
Then I create a sample database with some predefined students
view source
print?
01
02
03
04
Lewis
05
Franklin
06
07
08
Whitcomb
09
Donald
10
11
12
Kadi
13
Wadad
14
15
This database will be loaded into a list of student. Everytime when I add a new student, the new one will be added in this list and the list will be flushed back into XML database. However the predefined database locates outside the management field of application therefore we have no right to write data back. To write data back to XML file, I must store it in isolated storage of application and work with this replication.