3

I know the nested set model doesn't pertain to the C# language or LINQ directly... it's what I'm using to develop my web app.

For hierarchical data (categories with sub-categories in my case), I'm currently using something similar to the Adjacency List model. At the moment, I've only got 2 levels of categories, but I'd like to take it further and allow for n levels of categories using the nested set model.

I'm not quite clear on how to use it in a C# context. Here's the article I'm reading on the nested set model. Though this article cleared up my confusion some, I still have a big ?? in my head:

- Is inserting, updating or deleting categories tedious? It looks like the left and right numbers would require re-numbering... what would the LINQ queries look like for the following scenarios?

  • Delete a child node (re-number all node's left/right values)
  • Delete a parent node (what do you do with the orphans?)
  • Move a child node to a different parent node (renumber again)

If my understanding is correct, at all times the child node's left/right values will always be between the parent node's left/right values, am I correct?

Seems easy enough, if only the categories were static... most likely I need to spend more time to get my head around the concept.

Any help is greatly appreciated!

Chaddeus
  • 13,134
  • 29
  • 104
  • 162
  • Your undestanding is correct, having the child nodes carry ranges from inside the range of the parent node creates that "set" notion which is necessary for the algorithm to work. However, depending on the needs, you don't have to renumber the full set all the time since I don't see a problem in having gaps between the numbers as long as the basic rules remain (e.g. child in parent range, left smaller than right). – Lucero Mar 23 '10 at 00:41
  • Thank you... still trying to get a grasp of the concept. Seems like a really good way to model category/sub-categories to the nth level. – Chaddeus Mar 23 '10 at 01:25

0 Answers0