I am struggling with this left outer join with multiple conditions in LINQ. My initial SQL statement is as follows.
SELECT DISTINCT [Product].[prod_id],
    [Product].[brd_id],
    [Product].[prod_brdId],
    [Size].[size_id],
    [Size].[size_sort],
    [Bin].[bin_rack],
    [Bin].[bin_alpha]
  
  FROM [Proddetails]
  JOIN [Prodcolor]
  ON [Proddetails].[pcl_id] = [Prodcolor].[pcl_id]
  
  JOIN [Product]
  ON [Prodcolor].[prod_id] = [Product].[prod_id]
  
  JOIN [Size]
  ON [Proddetails].[pdt_size] = [Size].[size_id]
  
  LEFT OUTER JOIN [Bin]
  ON [Product].[prod_id] = [Bin].[prod_id]
  
  ORDER BY [Product].[brd_id], [Product].[prod_brdId], [Size].[size_sort]
And my corresponding LINQ statement in .NET
BinProds = (
from pd in applicationDbContext.Proddetails
  join pc in applicationDbContext.Prodcolors on pd.PclId equals pc.PclId
  join pr in applicationDbContext.Products on pc.ProdId equals pr.ProdId
  join sz in applicationDbContext.Sizes on pd.PdtSize equals sz.SizeId
  join bn in applicationDbContext.Bins on pr.ProdId equals bn.ProdId into ps                
  from bn in ps.DefaultIfEmpty()
  select new CoreBin
  {
    ... fields here
  }
).Distinct().OrderBy(i=>i.BrdId).ThenBy(j=>j.ProdBrdId).ThenBy(k=>k.SizeSort).ToList();
So, both of these execute successfully in SQL Server Studio and .NET respectively. However it's not giving me the exact result I'm looking for because it's missing one additional condition on the LEFT OUTER JOIN. Below is the one change I made to my SQL statement which gives me exactly what I want in SQL Server Studio. I just can't figure out how to adjust the LINQ to get the same result in my .NET project.
LEFT OUTER JOIN [Bin]
ON [Product].[prod_id] = [Bin].[prod_id]
AND [Bin].[size_id] = [Size].[size_id]
I'm hoping there is a reasonable adjustment. If you need my table outputs or db design, plz let me know.
 
    