I want to write one LINQ
query with left outer join.For this I am able to write the corresponding SQL
query which returns the desired output but the same in linq doesn't work for me.
This what my SQL looks like:
SELECT Table1.ID, Table1.Description
FROM Table1 LEFT OUTER JOIN
Table2 ON Table1.AID = Table2.AID AND Table1.TID = Table2.TID
WHERE (Table2.Status <> 'Using') OR (Table.Status IS NULL)
This query returns 7 records for me and that is what my requirement is.Now the same query I want to write with LINQ and this is what I tried with:
return (from t1 in db.Table1.AsEnumerable()
join t2 in db.Table2.AsEnumerable() on t1.AID equals t2.AID into outer
from item in outer.DefaultIfEmpty()
where item.TID == t1.TID
&& string.IsNullOrEmpty(item.Status) || item.Status != "Using"
select t1
);
But I have been facing issues with this.Here , it is not able to find item and thus returning
'Object reference not set to an instance of an object.'
What am I doing wrong over here????
I have been trying continuously but ended up with no solutions . So, any help in this would be highly appreciated.Thanks in advance..