将单父/多个子记录公开为一个 OData 条目
我有一个典型的父表/子表设置,其中父表中的一行可以通过外键拥有多个子表关联记录。示例:
父表:
身份证件
1 化学
2 生物
子表:
ID ParentId 主题
1 1 元素
2 1 元素周期表
3 2 细胞
4 2 剖析
我创建了一个基于父表和子表内部联接的视图 (Parent.Id = Child.ParentId),并将该视图作为 WCF 数据服务的一部分公开给实体数据模型。但是,当我在浏览器中查看 OData 源时,正如预期的那样,我看到多个条目重复每个关联子实体的父信息。
相反,我需要做的只是将每个父值及其父条目中的所有关联子记录显示一次。示例(使用伪 OData)
<entry>
<Book>Chemistry</Book>
<Subject>Elements</Subject>
<Subject>Periodic Table</subject>
</entry>
<entry>
<Book>Biology</Book>
<Subject>Cells</Subject>
<Subject>Dissections</Subject>
</entry>
有什么想法吗?
谢谢
I have a typical parent table/child table setup in which a row in the parent table can have multiple child table associated records by way of a foreign key. An example:
Parent Table:
ID Book
1 Chemistry
2 Biology
Child Table:
ID ParentId Subject
1 1 Elements
2 1 Periodic Table
3 2 Cells
4 2 Dissections
I have created a view based on inner joining the parent and child table (Parent.Id = Child.ParentId) and have exposed this view to an Entity Data Model as part of a WCF Data Service. However, when I view the OData feed in my browser, as expected, I see multiple entries repeating the parent information for each associated child entity.
Instead, what I need to do is only show each parent value once with all associated child records in their parent entry. Example (using pseudo OData)
<entry>
<Book>Chemistry</Book>
<Subject>Elements</Subject>
<Subject>Periodic Table</subject>
</entry>
<entry>
<Book>Biology</Book>
<Subject>Cells</Subject>
<Subject>Dissections</Subject>
</entry>
Any ideas?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将两个表公开为两个具有关系的实体集。因此父表与子表之间存在一对多关系。然后将该模型公开为 WCF 数据服务。然后运行如下查询(假设父实体集称为“Parents”,并且该父实体有一个名为“Children”的导航属性):
/父母?$expand=孩子
这将为您提供父母的提要,其中每个父母都会有其孩子的内联提要。
Expose your two tables as two entity sets with a relationship. So Parent would have a 1 - many relationship to Child table. Then expose that model as WCF Data Service. And then run a query like (assuming the Parent entity set is called Parents and that Parent entity has a navigation property called Children):
/Parents?$expand=Children
This will get you feed of parents where each parent will have an inline feed of its children.