Table : tblEmp
EmpId EmpName ManagerId
101 john Null
102 jack 101
The foll. query gives an error that the materialized value is null. Where am i going wrong. Please note that the EmpId & ManagerId are actually GUIDs in table.
Using c#, linq to entities
public DataTable GetData(guid id)
{
var qry = from e in MYDB.tblEmps.where(e=>e.EmpId==id)
join m in MYDB.tblEmps on e.ManagerId equals m.EmpId into emp_mgr
from m in emp_mgr.DefaultIfEmpty()
select new
{
name = m.empname ?? string.empty,
id = e.managerid //also tried e.managerid ?? guid.empty
}
DataTable dt = qry.ToDataTable();
return dt;
}