views:

468

answers:

1

Hi All,

I have a query (developing in linqpad):

DateTime currentDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
DateTime previousMonth = currentDate.AddMonths(-1);
DateTime previousMonthForAveragePrices = currentDate.AddMonths(-2);


var help =  from cd in CostDrivers.OfType<Commodity>() 
             where cd.isActive == true && 
             cd.arePricesCalculatedAverage == false
             from cp in cd.CostDriverPrices where cp.priceDate
== currentDate 
             select new {cd.costDriverID, cd.costDriverName, cd.isUpdatedMonthly, cd.arePricesCalculatedAverage,
               cp.costDriverPriceID, priceDate = cp.priceDate,
               cp.price, previousPriceDate = from cpc in cd.CostDriverPrices where cpc.priceDate == previousMonth 
               select new {previousPrice = cpc.price, previousPriceDate = cpc.priceDate}};

help.Dump();

What i need to do is return ALL costDrivers regardless of whether a price record exists on the given date (currentDate). I should point out there is an attempt at a subquery to grab another price record for a the currentDate -1 month. I've tried || null etc. no go. This is linq to entities. The query itself works.. it will only return result where there is a price. thanks!

thanks.

A: 

This should help http://stackoverflow.com/questions/1246021/left-outer-join-in-linq-to-entities

Additionally, I imagine you could also submit actual SQL to the EF if you wanted

http://msdn.microsoft.com/en-us/library/bb896272.aspx

Maslow