我有两个多到许多与有效载荷的实体,如下图所示:
因此,为了使存储在MasterPartNumber和一个部件号的大会 : MasterPartNumber.pn
,我用的导航属性ParentBOMs
,这是由关系式: MasterPartNumber.pnID = MasterPartsList.parentPnID
。 这给了我,亲组件下的所有子pnIDs。
为了让孩子的部件编号为组装 ,我用的是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对象包装的“吸”?
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`.
请帮忙! 谢谢 !