c# - LINQ连接多表

标签 c# linq join

我有 4 张 table :

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#编写连接? 谢谢。

最佳答案

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

关于c# - LINQ连接多表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17297295/

相关文章:

c# - 使用字符串格式格式化小数

C# 编译器 : CS0121: The call is ambiguous between the following methods or properties

c# - 如何将多个 linq 查询组合成一个结果集?

PHP MySQL 加入并输出为数组

mysql - 根据 child 及其 child 的条件获取父数据

mysql - 解释 JOIN 子句的结果

c# - 当我们在 C# 中重新分配数组时,数组的值是否被破坏?

C# 将字符串显式转换为枚举

c# - LINQ 内的规范与 EF 4.3

wpf - 如何将列表框选定的项目内容绑定(bind)到文本框?