Please help me convert this into LINQ. I am having trouble with the OUTER APPLY(that is meant to check if the record has children down the hierarchy).
SELECT phNode.Id,
phNode.[Description],
phNode.CreatedAt,
phNode.[Left],
phNode.[Right],
phNode.LastUpdated,
coalesce(c.HasChildren, 0) HasChildren,
phNode.LevelTypeId
FROM ProductHierarchy phNode ,
ProductHierarchy AS parent
OUTER APPLY
(
select top 1
1 as HasChildren
from ProductHierarchy ph2
where ph2.[Left] > parent.[Left] and
ph2.[Right] < parent.[Right]
) c
-- Get first child record. Returns null record if not found.
WHERE phNode.[left] BETWEEN parent.[left] AND parent.[Right]
AND parent.Id = 6
AND phNode.LevelTypeId = 4
ORDER BY phNode.[left];