2013-06-25 2 views
2

У меня есть 4 таблицы:LINQ объединить несколько столов

table1 
id1, 
fk_tbl2 //this is the foreign key to the "id" in table2 

table2 
id2, 
fk_tbl3 //this is the foreign key to the "id" in table3 

table3 
id3, 
fk_tbl4 //this is the foreign key to the "id" in table4 

table4 
id4, 
name 

Я хочу сделать несколько столов присоединиться, что, когда пользователь ввел «id4», я могу получить список записей в «table1».

Как написать заявку на участие в C#? Спасибо.

+0

Это зависит от ... У объектов для этих таблиц есть свойства, которые ссылаются друг на друга? – David

ответ

6
from t1 in table1 
join t2 in table2 on t1.fk_tbl2 equals t2.id2 
join t3 in table3 on t2.fk_tbl3 equals t3.id3 
join t4 in table4 on t3.fk_tbl4 equals t4.id4 
where t4.id4 == id 
select t1