我的 LINQ 语句有问题。
我有 3 个表:Examinations
、ExaminationProtocols
和 SampleTests
。
到目前为止,我一直使用此语句,因为我只需要前两个表的信息。
var baseQuery = from e in context.Examinations
join ep in context.ExaminationProtocols
on e.ID equals ep.ExaminationID into er
from r in er.DefaultIfEmpty()
select new { E = e, EP = r };
但现在我需要获取至少有 1 个带有字段 acccurate = true
的 SampleTest
的 ExaminationProtocols
。
SampleTest
和 ExaminationProtocols
之间的外键是
EP.ID equal ST.examinationProtocolID
我尝试加入语句中的第三个表,但似乎没有得到我想要的结果。
如果有人能给我提示,我将不胜感激。
最佳答案
这能为您提供所需的结果吗?
var baseQuery = from e in context.Examinations
join ep in context.ExaminationProtocols
on e.ID equals ep.ExaminationID into er
from r in er.DefaultIfEmpty()
join st in context.SampleTests
on r.ID equals st.examinationProtocolID
where st.acccurate
select new { E = e, EP = r };
关于c# - LINQ join 语句问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17987974/