c# - LINQ join 语句问题

标签 c# linq

我的 LINQ 语句有问题。

我有 3 个表:ExaminationsExaminationProtocolsSampleTests

到目前为止,我一直使用此语句,因为我只需要前两个表的信息。

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 = trueSampleTestExaminationProtocols

SampleTestExaminationProtocols 之间的外键是

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/

相关文章:

linq - 如何将 LINQ 查询结果转换为 List?

c# - 从 IEnumerable<IGrouping<,>> 创建 Lookup<,>

c# - 如何在 LINQ 查询中空检查 c# 7 元组?

linq - 我如何 LINQify 这个?

c# - 无法为 MediatR 设置起订量回调

c# - 引发订阅的异步事件后,对象会自动处理吗?

c# - 如何在我的项目中引用 TeamFoundation 程序集?

c# - 在 WPF Windows Phone 8 中销毁上一页 (NavigationService.GoBack())

c# - 以编程方式删除 XP/Vista/7 中的 TCP/IP 限制

c# - join 子句中的表达式之一的类型不正确