简体   繁体   中英

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:

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

I'm working with SQL Server, Entity Framework 5 and WPF and there are two primary use cases here:

1) Browse the entire tree

2) Browse/modify a single material_composite's tree.

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. I'd much rather be working with actual properties in POCO entities.

Does anyone have any concrete suggestions for how to get an arbitrarily deep hierarchy from a closure table into an application using 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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