I have the following models in my application:
public class Employee
{
public int PersonId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Benefits { get; set; }
}
public class Department
{
public int DeptID { get; set; }
public string DeptName { get; set; }
}
public class DeptEmp
{
public int PersonID { get; set; }
public int DeptID { get; set; }
}
I want to create a query, using Entity Framework, to select all columns from employee
with a condition that it retrieves only those employees that PersonId
has a relation with DeptId
in the DeptEmp
class and DepartId
from Department
has a relation with DeptId
in the DeptEmp
.
I have written the following LINQ statement:
var selectEmployees = from e in Employee
join d in DeptEmp on e.PersonId equals d.PersonId
join dd in Depatment on d.DeptId equals dd.DeptId
select new
{
e.FirstName,
e.LastName,
e.Benefits
};
but it is not working. Am I missing anything?