0

可能的重复:
如何在对象为复杂类型的实体框架中正确调用将 SProc 映射到 ObservableCollection 的函数

我需要将存储过程的输出(我相信它正确映射到复杂类型)放入 ObservableCollection 中,以便我可以使用 CollectionViewSource 将其绑定到 ListBox。我不知道还能尝试什么。

我的代码现在看起来完全像这样:

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
          CollectionViewSource GetParts_ResultViewSource = ((CollectionViewSource)(this.FindResource("getParts_ResultViewSource");

          GetPart_ResultViewSource.Source = this.selectedPnsCollection;
     }

     private ObservableCollection<GetParts_Result> selectedPnsCollection = new ObservableCollection<GetParts_Result>();

     private void shapeAttributeLBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
     {
          AttributeView selectedPartShape = this.shapeAttributeLBox.SelectedValue as AttributeView;
           if (shapeAttributeLBox.SelectedValue != null)
           {
                 selectedPnsCollection.Clear();
                 foreach (GetParts_Result result in 
                      this.myEntities.GetParts(selectedPartShape.attributeID, null));
                      {
                          selectedPnsCollection.Add(result);
                      }
              }
       }
      }

但是,我得到了一个内部异常,指出

 "{"Procedure or function 'GetParts' expects parameter '@@partShape', which was not supplied."}"

但它是提供的......或者我认为......并且作为一个 int,这是我的存储过程所期望的。


好吧,我在这里尝试的是使用 selectedPartShape.attributeID 和 null 参数来测试我的函数映射,因为我的 SProc 采用两个输入值,其中所有值都可以为空。

最后,我将使用另一个 listbox.SelectedValue 属性作为第二个输入参数。

我想我也可以手动提供一些相同的整数类型 ID(例如:this.myEntities.GetParts(5,161) 以返回每个具有这些 ID 属性的零件号列表。

4

1 回答 1

0

假设this.myEntities.GetParts(selectedPartShape.attributeID, null)映射到存储过程,我最好的猜测是因为 null 参数而导致错误。是AttributeViewattributeIdNullable<int>还是int?场地?

于 2012-08-10T05:52:10.260 回答