I was following the How-To Create a Basic Local Database Application for Windows Phone from MSDN, and I have a question about the creation of the table. Basically when they create the ToDoDataContext class they have a constructor and a static property for the connection string which makes sense, but then they place another property called ToDoItems (of type Table). Now logically it makes sense because this is a table for the ToDoItems but what doesn’t make sense is how we never actually assign it to the database. When I ran the program it just created the table. I was wondering when the database is created, does it automatically know to add that Table to the database just because its of that type or is it being added somewhere else?
EDIT: Here’s the specific piece I’m refering to:
public class ToDoDataContext : DataContext
{
// Specify the connection string as a static, used in main page and app.xaml.
public static string DBConnectionString = "Data Source=isostore:/ToDo.sdf";
// Pass the connection string to the base class.
public ToDoDataContext(string connectionString)
: base(connectionString)
{ }
// Specify a single table for the to-do items.
public Table<ToDoItem> ToDoItems;
}
You’re assigning
Table<ToDoItem>to the database by the very act of adding it in theDataContextderived class. The database code in the OS can inspect yourDataContextclass looking forTable<T>and then create the correct database infrastructure when you calldb.CreateDatabase().