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