1

我需要连接四个表Table1, Table2, Table3 & Table4,并需要表 1 中的所有数据以及表 2、3 和 4 中的匹配记录。这似乎很简单,但由于constraint表之间的关系,我无法获得正确的query.

Table2&Table3基本上是关联表,并保存Table1&之间的关联Table4。我正在尝试通过LINQ查询获得结果。

from t1 in context.Table1

join t2 in context.Table2 on t1.Id equals t2.RefId into t2Temp
from t2 in t2Temp.DefaultIfEmpty()

join t3 in context.Table3 on t1.Id equals t3.RefId into t3Temp
from t3 in t3Temp.DefaultIfEmpty()

join t4 in context.Table4
//here I want all the rows where t4.RefId equals to both t2.RefId & t3.RefId, so that I can get all the associations from table4
on ..... //this is where I got confused how to put the condition
into t4Temp
from t4 in t4Temp.DefaultIfEmpty()

表 1 和表 4 之间没有直接引用。我希望这能帮助你理解这个问题。如果需要,我会更乐意添加更多信息。

4

1 回答 1

-1

试试看:on t4.RefId equals t2.RefId || t4.RefId equals t3.RefId
然后在 t1 和 t4 中选择属性

于 2020-11-24T10:07:59.790 回答