如何将外部排除连接查询转换为LINQ

时间:2017-02-22 11:15:54

标签: c# sql linq

我想将此sql查询转换为linq:

SELECT Number
FROM Pager 
FULL OUTER JOIN Location
ON Pager.PagerId = Location.PagerId
FULL OUTER JOIN PersonCalls
ON Pager.PagerId = PersonCalls.PagerId
FULL OUTER JOIN Activity
ON Pager.PagerId = Activity.PagerId
WHERE (Pager.PagerId IS NULL OR Location.PagerId IS NULL) AND
(Pager.PagerId IS NULL OR PersonCalls.PagerId IS NULL) AND
(Pager.PagerId IS NULL OR Activity.PagerId IS NULL)

这可以正常工作。 但对于linq,我测试了这段代码:

var query = from Activity in db.Activity
 from Location in db.Location
from PersonCalls in db.PersonCalls
where
(Activity.Pager.PagerId == null ||
Location.PagerId == null) &&
 (Activity.Pager.PagerId == null ||
PersonCalls.PagerId == null) &&
(Activity.Pager.PagerId == null ||
Activity.PagerId == null)
select new {
 Activity.Pager.Number
}

给我没有结果!

0 个答案:

没有答案