Here is a linq inner join which returns what I want
var innerJoinQuery =
from employee in DbSet
join department in DbContext.Set<Departments>() on employee.DepartmentID equals department.ID
select new { ID = employee.ID, FirstName = employee.FirstName, LastName = employee.LastName, DepartmentID = employee.DepartmentID, DepartmentName = department.Name };
List<Employees> innerjoinresult_as_employees_list = innerJoinQuery.AsEnumerable().Cast<Employees>().ToList();
Model of Employees is:
public class Employees
{
public int ID { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
public int DepartmentID { get; set; }
[NotMapped]
public string DepartmentName { get; set; }
}
My problem is that I cannot have var innerJoinQuery as List<Employees>
so I can return it.
Does anyone knows how to do this?