简体   繁体   English

如何在实体框架中处理此层次结构

[英]How to handle this hierarchy in Entity Framework

I have a particular sort of data model that has to use a closure table due to the fact that nearly every material_composite is the root of its own tree, but can also be in the hierarchy of any other material_composite's tree: 我有一种特殊的数据模型,由于几乎每个material_composite都是其自己的树的根,但也可以位于任何其他material_composite的树的层次结构中,因此必须使用闭合表:

sql_model](![数据模型的权重是根元素而不是叶元素

I'm working with SQL Server, Entity Framework 5 and WPF and there are two primary use cases here: 我正在使用SQL Server,Entity Framework 5和WPF,这里有两个主要用例:

1) Browse the entire tree 1)浏览整棵树

2) Browse/modify a single material_composite's tree. 2)浏览/修改单个material_composite的树。

I can return the entire tree using SQL Server's FOR XML, but then I'm doing a lot of back and forth with the db whenever I want to look at the details/relations for a particular node in the hierarchy. 我可以使用SQL Server的FOR XML返回整个树,但是每当我想查看层次结构中特定节点的详细信息/关系时,我都会对数据库做很多来回操作。 I'd much rather be working with actual properties in POCO entities. 我宁愿使用POCO实体中的实际属性。

Does anyone have any concrete suggestions for how to get an arbitrarily deep hierarchy from a closure table into an application using Entity Framework? 对于使用Entity Framework如何将封闭表中的任意深层次结构放入应用程序中,是否有人有任何具体建议?

I oracle, I'd probably use some kind of connect by prior query to get the information you need. 我甲骨文,我可能会通过事先查询使用某种连接来获取所需的信息。 I think you can now do something similar in sqlserver with CTEs 我认为您现在可以在具有CTE的sqlserver中执行类似的操作

http://technet.microsoft.com/en-us/library/ms186243(v=sql.105).aspx http://technet.microsoft.com/zh-CN/library/ms186243(v=sql.105).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM