【发布时间】:2016-02-19 01:53:08
【问题描述】:
我有这个 LINQ(LINQ TO ENTITY):
var clientFullReview = (from cr in clientReview
join ir in inspectionReviews on cr.siteId equals ir.SiteId into g
from subsite in g.DefaultIfEmpty()
select new
{
clientId = cr.clientId,
clientName = cr.clientName,
siteId = cr.siteId == null ? -1 : cr.siteId,
inspectionReviewId = (subsite == null ? -1 : subsite.Id),
inspectionFrequency = (subsite == null ? -1 : subsite.FrequencyId),
isNormal = (subsite == null ? false : subsite.IsNormal)
});
在上面的链接中,我需要使用 where 子句。
inspectionReviews - 具有日期属性。 在上面的 LINQ 中,我只想加入具有特定日期的inspectionReviews 记录,如下所示:
var clientFullReview = (from cr in clientReview
join ir in inspectionReviews on cr.siteId equals
where ir.DateReview.Year == date.Year &&
ir.DateReview.Month == date.Month
into g
from subsite in g.DefaultIfEmpty()
select new
{
clientId = cr.clientId,
clientName = cr.clientName,
siteId = cr.siteId == null ? -1 : cr.siteId,
inspectionReviewId = (subsite == null ? -1 : subsite.Id),
inspectionFrequency = (subsite == null ? -1 : subsite.FrequencyId),
isNormal = (subsite == null ? false : subsite.IsNormal)
});
但是当我尝试使用 where 子句来实现它时,我得到了这个错误:
A query body must end with a select clause or a group clause
关于这个关键字:第二个 LINQ 中的 into。
所以我的问题是如何在实现联接时按日期过滤数据?
【问题讨论】: