如何从linq查询中检索聚合值
本文关键字:检索 查询 linq | 更新日期: 2023-09-27 18:28:30
我有以下查询:
from spl in SpeciesLists
join ar in Areas on spl.Station.Area equals ar.Id
join ground in Grounds on ar.Ground equals ground.Id
join re in Regions on ground.Region equals re.Id
where spl.Station.Trip.year ==2013
select new
{
SpciesCommonName = slp.Description,
Are = ar.description,
Ground = ground.Code,
NumberOfTripsInProtectedAreas = "To be calculated",
}
"行程"可以包括一个或多个站点。保护区域字段位于跳闸表上,可以是1或0。一个站点有一个或多个物种。
如何计算保护区内的出行次数?
提前感谢
您需要在where子句中添加ProtectedArea==1的条件。
此外,正如您在评论中所述,小组将通过:slp。说明、ar.Description和地代码
这是代码:
from spl in SpeciesLists
join ar in Areas on spl.Station.Area equals ar.Id
join ground in Grounds on ar.Ground equals ground.Id
join re in Regions on ground.Region equals re.Id
where spl.Station.Trip.year ==2013
&& spl.Station.Trip.ProtectedArea == 1
group spl by new { slp.Description, ar.description, ground.Code } into Result
select new
{
SpciesCommonName = Result.Key.Description,
Are = Result.Key.description,
Ground = Result.Key.Code,
NumberOfTripsInProtectedAreas = Result.Count()
}