Reputation: 22212
Scenario:
Employee: EmployeeId (PK) DepartmentId_FK (FK) Name and other fields
Department: DepartmentId (PK) CompanyId_FK (FK) Name and other fields
Company: CompanyId (PK) Name and other fields
How can I build a linq query that can join the three tables and returns EmployeeName, DepartmentName and CompanyName?
the following syntax does not work because there is no Navigation Property names Company
on Employee.cs
.
var model = DataContext.Employee
.Include("Employer")
.Include("Company");
What is the correct way to do this?
Upvotes: 2
Views: 3045
Reputation: 616
Try this :
var data = DataContext.Employees.Include("Department").Include("Department.Company");
But use this with caution as eager loading can hurt back if there is large amount of data.
Upvotes: 3