It seems you have a typo near tmp1
, you should do tree1.DefaultIfEmpty()
var qry = from c in ctx.comment
join p in ctx.professor
on c.PID equals p.ID into tree
join s in ctx.student
on c.SID equals s.ID into tree1
where c.VID == vID
from tmp in tree.DefaultIfEmpty()
from tmp1 in tree1.DefaultIfEmpty()
select new
{
Firstnmae = tmp.firstname ?? tmp1.firstname,
LastName = tmp.lastname ?? tmp1.lastname
};