0

I have an app built with C#. This app uses Entity Framework to query tables. In my databsae, I have two tables:

Department
----------
Id
Name
RemovedOn

Managers
---------
Id
Name
DepartmentId

When a user accesses the page, I have their ID. I need to get all of the departments associated with that manager. Currently, I have the following:

var managerDepartments = MyDb.Departments
  .Where(d => d.RemovedOn == null)
  .OrderBy(d => d.Name)
  .ToList();

This gives me all departments. However, it doesn't give me the list of departments specific to the manager. I know I can get the manager using something like this:

var manager = MyDb.Managers
  .Where(m => m.Id == this.CurrentUserId)
  .FirstOrDefault();

However, this doesn't bridge the two. I know I need to do a join. However, I don't know what that syntax looks like. Can someone please show me how to get all of the departments for a manager?

Thank you

Gary
  • 253
  • 3
  • 4
  • 11
  • 1
    Why are you using joins instead of defining relations and navigation properties between the entities? You could write `someManager.Department` and retrieve the department without joining. If you have to join in code, why use an ORM at all? – Panagiotis Kanavos Apr 10 '17 at 14:37
  • Not my downvote btw. This *is* a bug though – Panagiotis Kanavos Apr 10 '17 at 14:38

0 Answers0