Ok, so I will start by saying that I am new to all this stuff, and doing my best to work on this project. I have an employee object, that contains a supervisor field. When someone enters a search on my page, a datagrid displays employees whose name match the search. But, I need it to display all employees that report to them and a third tier of employees that report to the original employee’s underlings. I only need three tiers. To make this easier, employees only come in 3 ranks, so if rank==3, that employee is not in charge of others. I imagine the best method of retrieving all these employees from my employee table would be something like
from employee in context.employees
where employee.name == search || employee.boss.name == search ||
employee.boss.boss.name == search
But I am not sure how to make the orderby appear the way I want to. I need it to display in tiers. So, it will look like:
Big Boss-
Boss-
underling-
underling-
Boss-
underling-
Boss-
Boss-
Big Boss-
Like I said, there might be an easier way to approach this whole issue, and if there is, I am all ears. Any advice you can give would be HIGHLY appreciated.
This seems a difficult requirement to solve using any particular ORM framework, at least not in one easy step. A multi-step process is likely to be necessary.
Something roughly similar can be accomplished via an approach to iterate through the search results and finding their children (and children’s children), and flattening the hierarchy into a single list. An example implementation here, this one done using a plain in-memory list:
Sample data:
Process:
Show output:
Results:
And you can see it follows the top result, underling, underling’s underlings, next result, any underlings, etc. It works for any number of tiers.
I am not sure how that can be accomplished in an “order by” within Linq or even regular SQL, but that could only mean I’m not smart enough to do it rather than it just isn’t possible.