LINQ to SQL Left Join over Left Join c# -
i trying perform left join on existing left join lookup table.
something like:
(from m in maintablerepository.asqueryable() join st1 in subtable1repository.asquerable on m.id = s1.id grps1 s in grps1.defaultifempty() join lt1 in lookuptablerepository.asquerable on s.lkpid = lt1.id grplt1 lkp in grplt1.defaultifempty() select new { prop1 = m.prop1, prop2 = s.prop2, prop3 = lkp.prop3 }).tolist();
the issue query runs fine when remove left join on lookup table, though there not matching value in sub table.
however putting in place results in "object reference not set" error.
i have tried following, no go:
(from m in maintablerepository.asqueryable() join st1 in subtable1repository.asquerable on m.id = s1.id grps1 s in grps1.defaultifempty() join lt1 in lookuptablerepository.asquerable on s.lkpid = lt1.id grplt1 lkp in grplt1.defaultifempty() s!=null && lkp!=null select new { prop1 = m.prop1, prop2 = (s==null)?string.empty:s.prop2, prop3 = (lkp==null)?string.empty:lkp.prop3 }).tolist();
if first left join results in null, how 1 join on it?
the issue s.lkpid = lt1.id s being null. try placing s != null the 1 below
(from m in maintablerepository.asqueryable() join st1 in subtable1repository.asquerable on m.id = s1.id grps1 s in grps1.defaultifempty() s!=null join lt1 in lookuptablerepository.asquerable on s.lkpid = lt1.id grplt1 lkp in grplt1.defaultifempty() lkp!=null select new { prop1 = m.prop1, prop2 = (s==null)?string.empty:s.prop2, prop3 = (lkp==null)?string.empty:lkp.prop3 }).tolist();
please mark post answered if helped you
Comments
Post a Comment