I've created a local database for my Windows Phone 7 app and I created one table using the tutorial on msdn. I have a problem with a second table how do I add it ? When I make another class with Linq do I need to use the same datacontext class and just add another Table? I tried so many thing I tried to create it the same way I did the first table but nothing seems to work my app just crashes. Please help
Asked
Active
Viewed 969 times
1 Answers
1
Assuming that the program runs OK with one table (so you know your connection string and datacontext are OK for one table), then yes when you add a second table, you need to write an additional class with a [Table] attribute and you need to add a property to the datacontext.
public class ATestDataContext : DataContext
{
public ATestDataContext(string connectionString) : base(connectionString)
{
}
public Table<FTable> FirstTable
{
get
{
return this.GetTable<FTable>();
}
}
public Table<STable> SecondTable
{
get
{
return this.GetTable<STable>();
}
}
}
[Table]
public class FTable : INotifyPropertyChanged, INotifyPropertyChanging
{...}
[Table]
public class STable : INotifyPropertyChanged, INotifyPropertyChanging
{...}
If you are looking to set up relationships between the tables, such as master-detail, then there are other things you need in your classes. One of the best examples I came across is here: http://windowsphonegeek.com/articles/Windows-Phone-Mango-Local-Database-mapping-and-database-operations

flarebear
- 123
- 8