I'm trying to do a left outer join with linq on on 2 Lists of the same type. I've been following the syntax I see in examples online, but my left join is ending up with a count of 0 values. The 2 lists being joined are not empty so I should definitely be getting some results however I can't seem to determine what is wrong with the syntax. Any help would be greatly appreciated.
var leftOuterJoin = from r in received
join rs in reserved.DefaultIfEmpty()
on new {a = r.ProductId, b = r.WarehouseSectionId } equals new { a = rs.ProductId, b = rs.WarehouseSectionId } into joinedL
from rs in joinedL.DefaultIfEmpty()
select new
{
SKU = r.SKU,
ProductName = r.ProductName,
QTY = r.QTY,
PhysicalStock = (rs.QTY != null && rs.QTY > 0) ? r.QTY + rs.QTY : r.QTY,
WarehouseSection = r.WarehouseSection,
WarehouseName = r.WarehouseName,
ProductId = r.ProductId,
WarehouseSectionId = r.WarehouseSectionId
};
Edit: I am able to make the query return values by commenting out Physical Stock in the select but I can still not figure out a reason for this. It looks like this error is caused by using the rs.qty variable, if I change any of the fields to rs.qty, it will trigger the same error. All of the rs.qty fields have values however there are more r items than rs items
//PhysicalStock = (rs.QTY != null && rs.QTY > 0) ? r.QTY + rs.QTY : r.QTY,