join-clause ::= join itemName in srcExpr on keyExpr equals keyExpr
(into itemName)?
Let's select all department's names and managers of department. join clause is used to combine 3 tables with many-to-many relationship.
var result =
from dep in emp.Departments
join dm in emp.DEPtManager on dep.DEPtNo equals dm.DEPtNo
join chef in emp.Employees on dm.EmPNo equals chef.EmPNo
select new { dep.DEPtName, chef.LastName };
foreach (var a in result)
Console.WriteLine(a);
Listing 3.
In our case relationships are defined using parent/child lists and query can be simplified. The DataContext hides details of implementation.var result =
from dep in emp.Departments
from dm in dep.DEPtManager
select new { dep.DEPtName, dm.Employees.LastName };
foreach (var a in result)
Console.WriteLine(a);
Listing 4.
Result will be the same:
No comments:
Post a Comment