0

Example: A is a manager, B is A's subordinate, and C is B's subordinate.

What I need to do is to display a list of subordinates that shows on A's screen which are B and C's info. This is what I have now that will display whoever has A as their manager which are B and etc.

 displayList = db.LeaveApplicationDbSet
      .Where(l => db.EmployeeDbSet
                .FirstOrDefault(e => e.user_id.Equals(l.UserId))
                .manager_id.Equals(userDetails.EmployeeId)
      );

Any idea on how I can get the grand child portion of the hierarchy?? e.g.: A -> B -> C so from A's view he/she should be able to see B and C's info

Update:

public class MysqlDbContext: DbContext
{   
    public MysqlDbContext() : base(dbName)
    { }

    public DbSet<Employee> EmployeeDbSet { get; set; }
}

public class Employee : IValidatableObject
{
    [Column("id")]
    public int id { get; set; }

    [Required]
    [Column("user_id")]
    public string user_id { get; set; }

    [Column("full_name")]
    public string full_name { get; set; }

    [Required]
    public string manager_id { get; set; }
}
Eric Herlitz
  • 25,354
  • 27
  • 113
  • 157
DatB
  • 51
  • 6

1 Answers1

0

An easy solutions would be to separate it in different queries. First you query the employees that has person A as manager. Then you query for employees that has any of B as manager. Something like this:

//All employees of person A 
var B = db.LeaveApplicationDbSet.Where(e => e.manager_id == "A");
var C = new List<Employee>();

//All employees from B
foreach(var i in B){
var D = db.LeaveApplicationDbSet.Where(e => e.manager_id == i.id).ToList();
C.AddRange(D);

}

LordSilvermort
  • 237
  • 2
  • 8