Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从linq查询中检索聚合值?_C#_Linq - Fatal编程技术网

C# 如何从linq查询中检索聚合值?

C# 如何从linq查询中检索聚合值?,c#,linq,C#,Linq,我有以下疑问: 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.

我有以下疑问:

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.Description、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()
               }

您需要在where子句中添加ProtectedArea==1的条件

正如您在评论中所述,该组将由以下人员组成:slp.Description、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()
               }

您的选择列表包含“slp.Description”,这意味着您的结果将包含物种列表而不是Trips列表!如果你想对旅行进行汇总,我相信你的结果应该有所不同。请您澄清一下好吗?正确,但这是因为我需要按所选列对结果进行分组。我知道这在psot中被省略了。所以,您希望聚合值位于三列上吗?是的,这正是我需要的。您的选择列表包含“slp.Description”,这意味着您的结果将包含物种列表而不是Trips列表!如果你想对旅行进行汇总,我相信你的结果应该有所不同。请您澄清一下好吗?正确,但这是因为我需要按所选列对结果进行分组。我知道这在psot中被省略了。所以,你希望聚合值在三列上吗?是的,这正是我需要的。嗨,阿德尔,这看起来非常优雅。我将实施它,并让您知道这是否解决了我的问题。非常感谢你的努力。嗨,阿德尔,这看起来非常优雅。我将实施它,并让您知道这是否解决了我的问题。非常感谢你的努力。