C# 难以订阅SelectedItem属性作为EF4中存储过程的输入,通用存储库模式/MVVM

C# 难以订阅SelectedItem属性作为EF4中存储过程的输入,通用存储库模式/MVVM,c#,stored-procedures,entity-framework-4,repository-pattern,complextype,C#,Stored Procedures,Entity Framework 4,Repository Pattern,Complextype,我使用MsDesktop堆栈示例创建模式并为实体集建立视图/视图模型/存储库,该实体集的PrimaryKey(称为PartNumber)使用存储过程函数映射映射到ComplexType的许多属性属性 我很容易就能订阅RaisePropertyChangedEvent(“部件”)来填充列表框,但无法获得: public Part SelectedPart { get { return p_SelectedPart; } set {

我使用MsDesktop堆栈示例创建模式并为实体集建立视图/视图模型/存储库,该实体集的PrimaryKey(称为PartNumber)使用存储过程函数映射映射到ComplexType的许多属性属性

我很容易就能订阅RaisePropertyChangedEvent(“部件”)来填充列表框,但无法获得:

    public Part SelectedPart
    {
        get { return p_SelectedPart; }

        set
        {
            base.RaisePropertyChangingEvent("SelectedPart");
            p_SelectedPart = value;
            base.RaisePropertyChangedEvent("SelectedPart");
        }
    }
当我在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;
        }
其中ReturnExtendedProperties()定义为:

 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);
          }
       }
  }
public static void ReturnExtendedPartProperties(MainWindowVM MainWindowVM)
{
MyEntities MyEntities=新MyEntities();
mainWindow.ReturnAttsPerPn_结果=新的ObservableCollection();
如果(mainWindowVM.SelectedPart!=null)
{
mainwWindowVm.ReturnAttsPerPn_Result.Clear();
foreach(ReturnAttsPerPn_结果属性结果在myEntities.ReturnAttsPerPn(mainWindowVM.SelectedPart.PnID))
{ 
mainWindowVM.ReturnAttsPerPn_Result.Add(属性结果);
}
}
}
调试时,“我的局部变量”窗口中没有SelectedPart属性的数据,但零件对象的ObservableCollection在那里(这很明显,因为我可以看到这些数据)。此外,我甚至从未涉及到“SelectedPart”的情况,只有OnPropertyChanged方法中的“Part”

我的主要问题是,(作为初学者,请原谅我缺乏清晰度):如何有效地“捕获”SelectedPart属性的值并将其提供给存储过程,并将输出用作集合

感谢阅读,非常感谢您的帮助:)


Edit::Changed Title

尴尬地发现了我的错误,这只是绑定路径中的语法错误,我没有发现(也没有发布)。对于任何感兴趣的人来说,这是存储过程结果获取方法的更清晰版本,可能对某些人有用:

 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);
                  }
              } 
       }
 }
public static void ReturnExtendedPartProperties(MainWindowVM MainWindowVM)
{
mainWindow.ReturnAttsPerPn_结果=新的ObservableCollection();
使用(var myEntities=new myEntities())
{
var results=myEntities.ReturnAttsPerPn(mainWindowVM.SelectedPart.PnID)
如果(mainWindowVM.SelectedPart!=null)
{
mainWindowVM.ReturnAttsPerPn_Result.Clear();
foreach(返回ATTSPERPN_结果属性结果中的结果)
{
mainWindowVM.ReturnAttsPerPn_Result.Add(属性结果);
}
} 
}
}