Linq中的left join

时间:2021-10-31 17:31:29

left join

            var custs = from c in db.T_Customer
join u in db.Sys_User on c.OwnerId equals u.Id into temp
from t in temp.DefaultIfEmpty() //left join
where (c.PhoneNum1 == phone || c.PhoneNum2 == phone || c.PhoneNum3 == phone)
select new
{
CustName = string.IsNullOrEmpty(c.CustName) ? "匿名" : c.CustName,
UserName = t == null ? "暂无" : t.Name//这里主要第二个集合有可能为空。需要判断
};