0

I know there are lot of links related to this issue but my scenario is somewhat weird. tbEHDepartments and tbEHAccesses tables are newly added hence reference of them in tbEHUsers table is null. As far my understanding and search NULL values in the column is the reason for error but works in scenario when ManagerID is null. I mean to say if i remove grp1.DeptID from select query everything works properly even if ManagerId is null.

var data = from t in db.tbEHUsers.DefaultIfEmpty()
           join t3 in db.tbEHUsers.DefaultIfEmpty() on t.ManagerID equals t3.UserID into t2
           from grp in t2.DefaultIfEmpty()

           join d in db.tbEHDepartments.DefaultIfEmpty() on t.DeptID equals d.DeptID into t4
           from grp1 in t4.DefaultIfEmpty()

           join a in db.tbEHAccesses.DefaultIfEmpty() on t.AccessID equals a.AccessID into t5
           from grp2 in t5.DefaultIfEmpty()
           orderby t.FirstName
           select new { t.UserID, t.UserName, t.FirstName, t.LastName, t.Email, t.ManagerID, TeamLead = grp.FirstName + " " + grp.LastName, grp1.DeptID };//, grp1.DeptName, grp2.AccessID, AccessName=grp2.Name };

var dt = Utility.ToDataTable(data);
4

1 Answer 1

0

Is ManagerID and USerID same data type? Is one of them Nullable hence "Int32?" ?

Sometimes an error like that isn't thrown until data met in the database forces the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.