Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 844871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:21:21+00:00 2026-05-15T06:21:21+00:00

Ok, so I will start by saying that I am new to all this

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:21:22+00:00Added an answer on May 15, 2026 at 6:21 am

    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:

    class Employee
    {
        public int Id { get; private set; }
        public int? BossId { get; private set; }
        public string Name { get; private set; }
    
        public Employee(int id, int? bossId, string name)
        {
            Id = id;
            BossId = bossId;
            Name = name;
        }
    }
    

    Sample data:

    List<Employee> employees = new List<Employee>();
    employees.Add(new Employee(1, null, "Tom Smith"));
    employees.Add(new Employee(2, null, "Susan Jones"));
    employees.Add(new Employee(3, 1, "Sally Davis"));
    employees.Add(new Employee(4, 1, "Robert Roberts"));
    employees.Add(new Employee(5, 3, "John Smith"));
    employees.Add(new Employee(6, 2, "Tonya Little"));
    employees.Add(new Employee(7, 3, "Ty Bell"));
    employees.Add(new Employee(8, 4, "Helen Andrews"));
    employees.Add(new Employee(9, 2, "Matt Huang"));
    employees.Add(new Employee(10, 6, "Lisa Wilson"));
    

    Process:

    string searchTerm = "Smith";
    
    var searchResults = employees.Where(e => e.Name.Contains(searchTerm));
    
    List<Employee> outputList = new List<Employee>();
    
    Action<IEnumerable<Employee>, List<Employee>> findUnderlings = null;
    findUnderlings = (input, list) =>
    {
        foreach (Employee employee in input)
        {
            list.Add(employee);
            var underlings = employees.Where(e => e.BossId == employee.Id);
            findUnderlings(underlings, list);
        }
    };
    
    findUnderlings(searchResults, outputList);
    

    Show output:

    foreach (Employee employee in outputList)
    {
        Console.WriteLine("{0}\t{1}\t{2}", employee.Id, employee.Name, employee.BossId);
    }
    

    Results:

    1       Tom Smith
    3       Sally Davis     1
    5       John Smith      3
    7       Ty Bell 3
    4       Robert Roberts  1
    8       Helen Andrews   4
    5       John Smith      3
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an ASP.Net MVC project that will start with a single web server
Ok, lemme start out by saying Im new to this! LOL I have done
I'm going to start this off by saying that I am new to GLSL
I will start by saying that I am completely new to WPF. But, I
I will start by saying that I don't think what I want can be
I will start new project which is based on ASP.NET MVC 3 using C#
I will start new PDA project on the windows mobile and compact framework 2.0
I have an asp.net page that calls a dll that will start a long
First for all I would like to start by saying I am relatively new
So I'm going to qualify this by saying that I'm new to NASM and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.