我有一个查询(在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();
我需要做的是返回所有costDrivers,而不管在给定日期(currentDate)是否存在价格记录。我应该指出的是,有人试图使用子查询来获取currentDate -1月份的另一个价格记录。我已尝试|| null等,不能继续。这是linq to entities。查询本身是有效的。它将只返回有价格的结果。谢谢!
谢谢。
发布于 2010-02-12 02:50:36
这应该会对Left Outer Join in Linq-To-Entities有所帮助
此外,如果您愿意,我想您还可以向EF提交实际的SQL
http://msdn.microsoft.com/en-us/library/bb896272.aspx
https://stackoverflow.com/questions/1267557
复制相似问题