我有下面的表结构,它已导入到 Entity Framework 中。我需要编写一个 LINQ 查询,我在其中选择表 1 的实体,其中表 2 中的一个字段等于 true,表 3 中的一个字段等于特定的 GUID。
有人可以帮忙吗?
谢谢。
最佳答案
尝试:
from t3 in dataContext.Table3
where t3.Guidfield == someGuid
from t2 in t3.Table2
where t2.Field // boolean field is true
select t2.Table1;
编辑: 根据要求,等效的 lambda 表达式语法:
dataContext.Table3.Where(t3 => t3.Guidfield == someGuid)
.SelectMany(t3 => t3.Table2)
.Where(t2 => t2.Field)
.Select(t2.Table1);
关于linq - 如何在针对 Entity Framework 的 LINQ 查询中执行 "join",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2225099/