LINQ加入多桌 [英] LINQ join multi table

查看:109
本文介绍了LINQ加入多桌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个表:

  table1的
ID1,
fk_tbl2 //这是国外关键在表2

表2
ID2的ID,
fk_tbl3 //这是在表3

外键的ID表3
ID3,
fk_tbl4 //这是在表4

表4
ID4外键的ID,
名称

我想打一个多表连接,当用户输入ID4,我能得到记录列表在表1。



如何写在C#中加入?
感谢。


解决方案

 从表1 
T1加盟T2在表2 t1.fk_tbl2等于t2.id2
在表3 t2.fk_tbl3加入T3等于t3.id3
在t3.fk_tbl4表4加入T4等于t4.id4
,其中t4.id4 == ID
选择T1


I have 4 tables:

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

I want to make a multi table join, that when the user input "id4", i can get a list of record in "table1".

how to write the join in C#? Thanks.

解决方案

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

这篇关于LINQ加入多桌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆