2

We have a table structure like an order table with an order lines table and we define a hierarchy of items in the table according to the user requirements by storing a string made up of a comma separated list of record id’s at each level. This allows the user to “re-order” their lines as needed.

e.g.

A Hierarchy string on the order could be something like “3,2,4” meaning that its top level children are lines 3,2,4 (in that order). The first order line might have its own hierarchy string such as “5,6” indicating that it has nested children that should appear below it.

We want to return this data structure as a flat list of objects in order with a marker of how “deep” it is in the hierarchy. For example if the data looks like this:

Header: enter image description here Lines: enter image description here

We want a flat list like this (in this order):

{Line1Object}, 1
{Line3Object}, 2
{Line2Object}, 2
{Line4Object}, 2
{Line5Object}, 3
{Line6Object}, 3

Can this be done in one hit with some kind of joining process in Entity Framework instead of looping through our records and building this up as we go or are we being too ambitious?

Hambone
  • 15,600
  • 8
  • 46
  • 69
Raheem
  • 21
  • 1
  • Not an answer to the question but there's some good background reading on this conceptual question. https://stackoverflow.com/questions/192220/what-is-the-most-efficient-elegant-way-to-parse-a-flat-table-into-a-tree?rq=1 – Mordy Nov 20 '18 at 16:48

0 Answers0