Question

I used the MsDesktop Stack example here to create my pattern and establish a view/viewmodel/repository for an entity set, whose PrimaryKey (called PartNumber) maps to many Attribute properties of ComplexType using a Stored Procedure Function Mapping.

I was easily able to subscribe to the RaisePropertyChangedEvent("Parts") to populate a listbox, but am unable to get:

    public Part SelectedPart
    {
        get { return p_SelectedPart; }

        set
        {
            base.RaisePropertyChangingEvent("SelectedPart");
            p_SelectedPart = value;
            base.RaisePropertyChangedEvent("SelectedPart");
        }
    }

when I subscribe to it in my OnPropertyChangedEvent:

 void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
        switch (e.PropertyName)
        {
            case "SelectedPart":

                /* When we select a Part, we need to configure the view model
                    * to display the selected Part's attributes. */

                VMSProcServices.ReturnExtendedPartProperties(this);

                break;

            case "Parts":

                /* When we load a Parts collection from the data store, we replace 
                    * the existing collection in the Parts property. After we do that, 
                    * we need to subscribe to the CollectionChanging event of the new
                    * collection. */

                this.Parts.CollectionChanging += OnPartsCollectionChanging;
                break;
        }

where ReturnExtendedProperties() is defined as:

 public static void ReturnExtendedPartProperties(MainWindowVM mainWindowVM)
 {
      MyEntities myEntities = new MyEntities();
      mainWindow.ReturnAttsPerPn_Result = new ObservableCollection<ReturnAttsPerPn_Result>();
      if (mainWindowVM.SelectedPart != null)
      {
          mainwWindowVm.ReturnAttsPerPn_Result.Clear();
          foreach (ReturnAttsPerPn_Result attResult in myEntities.ReturnAttsPerPn(mainWindowVM.SelectedPart.PnID))
          { 
              mainWindowVM.ReturnAttsPerPn_Result.Add(attResult);
          }
       }
  }

When debugging this, there is no data in my Locals window for the SelectedPart property, but the ObservableCollection of Part objects is there (which is obvious because I can see this data). Also, I never even step into the case of "SelectedPart", only "Part" on my OnPropertyChanged Method.

My main question is, (and excuse my lack of articulation as I am a beginner): How do I effectively "catch" the value of the SelectedPart property and feed it to my Stored Procedure, and use the output as a collection?

Thanks for reading, any help greatly appreciated :)

Edit:: Changed Title

Was it helpful?

Solution

Embarrassingly found my mistake, which was just a syntax error in the binding path that I didn't catch (and is not posted. For anyone who is interested, this is a cleaner version of stored procedure results acquiring method that may be of some use to someone:

 public static void ReturnExtendedPartProperties(MainWindowVM mainWindowVM)
  {
       mainWindow.ReturnAttsPerPn_Result = new ObservableCollection<ReturnAttsPerPn_Result>();
       using (var myEntities = new MyEntities())
       {
             var results = myEntities.ReturnAttsPerPn(mainWindowVM.SelectedPart.PnID)
             if (mainWindowVM.SelectedPart != null)
             {
                  mainWindowVM.ReturnAttsPerPn_Result.Clear();
                  foreach (ReturnAttsPerPn_Result attresult in results)
                  {
                        mainWindowVM.ReturnAttsPerPn_Result.Add(attresult);
                  }
              } 
       }
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top