首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Linq to Entities Left Entities/ Subquery?

Linq to Entities Left Entities/ Subquery?
EN

Stack Overflow用户
提问于 2009-08-12 17:28:20
回答 1查看 1.6K关注 0票数 1

我有一个查询(在linqpad中开发):

代码语言:javascript
复制
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。查询本身是有效的。它将只返回有价格的结果。谢谢!

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2010-02-12 02:50:36

这应该会对Left Outer Join in Linq-To-Entities有所帮助

此外,如果您愿意,我想您还可以向EF提交实际的SQL

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1267557

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档