我有一个查询(在 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}};
帮助.转储();
我需要做的是返回所有 costDrivers,无论给定日期(currentDate)是否存在价格记录。我应该指出,有一个子查询尝试获取 currentDate -1 月的另一个价格记录。我试过了|| null 等不去。这是实体的 linq。查询本身有效.. 它只会返回有价格的结果。谢谢!
谢谢。