我有以下表结构已导入实体框架。我需要编写一个LINQ查询,我在其中选择Table1的实体,其中Table2中的字段等于true,表3中的字段等于特定的GUID。
有人可以帮忙吗?
谢谢你。
答案 0 :(得分:5)
尝试:
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);
答案 1 :(得分:0)
from t1 in table1
join t2 in table2
on t1.table1PK equals t2.table1PK
join t4 in table4
on t2.table2PK equals t4.table2PK
join t3 in table3
on t3.table3PK equals t4.table3PK
where t2.randomBoolColumn == true && t3.GUID == myGUIDVariable
select t1;