Try this query and let me know if it works. I changed the connection to a where clause, this should eliminate all the complex subqueries that LINQ generates when translating to SQL.
I'm not sure if I got the LEFT OUTER JOIN correctly. I just included an OR condition that checks if one side exists.
from p in dbFAS.Products from ltt in dbFAS.LevelThreeTracking where p.CategoryName == "CategoryName" && (p.Date == ltt.Date || p.Date) && (p.CategoryName == ltt.CategoryName || p.CategoryName) && (p.ProductName == ltt.ProductName || p.ProductName) && p.Quantity > 0 group p by new {p.Date, p.CategoryName, p.ProductName, p.Quantity, p.Sales, ltt.Level3} into gp select new { gp.Key.Date, gp.Key.CategoryName, gp.Key.ProductName, Quantity = gp.Sum(hp=>hp.Quantity), TotalSales = gp.Sum(hp=>hp.Sales), ltt.Level3 };
EDIT: I thought about this a little more, and it can be a little more clear, and it can even compile! (The latter will not be due to the proposals ||)
from gp in (from p in dbFAS.Products join ltt in dbFAS.LevelThreeTracking on new {p.Date, p.CategoryName, p.ProductName} equals new {ltt.Date, ltt.CategoryName, ltt.ProductName} into temp where p.CategoryName == "CategoryName" && p.Quantity > 0 from t in temp.DefaultIfEmpty() select new { p.Date, p.CategoryName, p.ProductName, p.Quantity, p.Sales, t.Level3 }) group gp by new {gp.Date, gp.CategoryName, gp.ProductName, gp.Level3} select new { gp.Key.Date, gp.Key.CategoryName, gp.Key.ProductName, Quantity = gp.Sum(hp=>hp.Quantity), TotalSales = gp.Sum(hp=>hp.Sales), gp.Level3 }
Noah Dec 31 '09 at 18:52 2008-12-31 18:52
source share