如何将以下LINQ查询重写为普通T-SQL?
var list = (from t in context.ParentTable
where t.ChildRecords.Count == t.ChildRecord.Count( c => c.BooleanColumn )
select t).ToList();
预先感谢...
类似的东西,但是您需要确定ParentTable
和ChildRecord
表之间的关系才能使其正常工作,我只是在猜测cr.ParentTableId = pt.ParentTableId
部分。
select pt.*
from ParentTable pt
where not exists
(select 1
from ChildRecord cr
where cr.ParentTableId = pt.ParentTableId
and cr.BooleanColumn = 0)
在侧面注释中,LINQ可以更改为以下内容。
var list = (from t in context.ParentTable
where t.ChildRecords.All(c => c.BooleanColumn)
select t).ToList();