Reputation: 3601
I've a linq query over two Entities like this
IQueryable<Employee> employees = CreateObjectSet<Employee>().AsQueryable();
IQueryable<Department> depts = CreateObjectSet<Department>().AsQueryable();
var result = (from employee in employees
join dept in depts
on emp.DeptID equals dept.ID
select employee
My Employee entity has a navigation property for Department and return its whole object, but this query does not return the Department info, i guess i've to set the values in the select statment, something like this
var result = (from employee in employees
join dept in depts
on emp.DeptID equals dept.ID
**** employee.Dept=dept ****
select employee
I dont want to set all the properties of Employee class and hence return that new object, please tell me some better approach.
Thanks
Upvotes: 1
Views: 880
Reputation: 17752
My understanding is you want to select all the employees along with their departments (correct me if I am wrong). If you have a navigational property, you won't need a join at all. You can use Include
like this:
List<Employee> employeesWithDepartments = CreateObjectSet<Employee>().
Include(e => e.Department).
ToList();
Upvotes: 1
Reputation: 5688
couldnt you use "let" statement as a hack ?
var result = (from employee in employees
join dept in depts
on employee.DeptID equals dept.ID
let notUtile = employee.Dept=dept
select employee);
Upvotes: 1