我有两个带有有效负载实体的多对多,如下所示:
因此,要使用零件号制作存储在 MasterPartNumber 中的组件MasterPartNumber.pn
,我使用导航属性ParentBOMs
,它由关系给出:
MasterPartNumber.pnID = MasterPartsList.parentPnID
。这给了我该父程序集下的所有子 pnID。
要获取该组件的子零件编号,我使用由ChildPn
定义的导航属性MasterPartsList.pnID = MasterPartNumber.pnID
。
请注意,顶级装配项目未在 MasterPartsList 中列出(它们的 parentPnID 为空)。
我的 TreeView HierarchicalDataTemplate 绑定是:
<TreeView x:Name="AssemblyTreeView"
ItemsSource="{Binding BOMItems}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:MasterPartNumber}"
ItemsSource="{Binding ParentBOMs.ChildPn}">
<TextBlock Text="{Binding pn}" />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
我认为这是正确的。我可以单步调试调试器,并看到为每个具有子信息的项目填充了整个 BOMItem 导航属性 (ParentBOM.ChildPn.pn)。
为什么我无法在 TreeView 中看到这些子属性?!
What I should get:
Root Assembly
--Sub Assembly
----Sub Assembly
------Child (n-levels deep)
和
我实际得到的:
Root Assembly
我需要额外的转换器吗?我是否需要进一步定义我的 ObservableCollection 对象包装器的“getter”?
Known possible sources of the problem:
1. Entity Framework is lazy loading, and just hasn't loaded the navigation properties I see in
the debugger being populated. (No, set LazyLoading to false.)
2. My HierarchicalDataTemplate isn't probing for children just on the fact that it has children
-- aka it only understands to switch the binding path when a new DataType is available, or
something like that. (Not likely, because I've seen HierarchcialDataTemplates for self-referencing entities of a single entity type.)
What I have right:
1. I can cascade down the binding route I told my TreeView to take in the debugger.
Parent `pn` is populated as well as its `ParentBOMs.ChildPn.pn`.
请帮忙!谢谢 !