Class used in Class

Dec 25, 2010 at 6:41 PM
Edited Dec 26, 2010 at 12:09 PM

myKey = App.Database.Save(App.ViewModel.Items[index]);
EventViewModel wVM = App.Database.Load<EventViewModel>(myKey);

------------------------------------------------------------

public class EventViewModel : INotifyPropertyChanged
{
    public EventViewModel()
    {
        this.Arrows = new ObservableCollection<Arrow>();
    }
    private int _id;
    public int Id
    {
        get { return _id; }
        set
        {
            if (value != _id)
            {
                _id = value;
                NotifyPropertyChanged("Id");
            }
        }
    }

    public ObservableCollection<Arrow> Arrows { get;  set; }

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (null != handler)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

public class Arrow : INotifyPropertyChanged
{

   public int Round { get; set; }
   public int End { get; set; }
   public string Archer { get; set; }
   public int ArrowInEnd { get; set; }

   public double MetaX { get; set; }
   public double MetaY { get; set; }
   public byte Score { get; set; }
}

-----------------------------------------------------------------------------------------

I can see my Arrows being in my EventviewModel item when saving in first line.

In the second line I can find everything else not but my  Arrows...

Can I get this thingie to work in someway or should I create one Event table and another Arrow table and rather use a join to connnect them?

Would be very interesting if the DB supported this kind of hierarkikal structure...

BTW Thanks for a very interesting wp7 dB ....

Merry Christmas...

Harald

Dec 26, 2010 at 12:05 PM

Hi
Think I got it.

All in the Tuple in the arrow  table def:

CreateTableDefinition<EventViewModel,int>(i=>i.Id)
                  .WithIndex<EventViewModel, DateTime, int>(EVENT_DATE, c => c.EventDate),

CreateTableDefinition<Arrow,string>(c =>Tuple.Create(Tuple.Create(c.Round,c.End).ToString(),c.Archer,c.ArrowInEnd).ToString()

Coordinator
Dec 26, 2010 at 3:45 PM

Right - any complex classes should either be defined as a table (will create a foreign key type relationship) or have a serializer registered to help Sterling know the right (and most efficient) way to serialize.