C# Linq get数组和sum作为返回数据集的一部分
我有一个Linq查询:C# Linq get数组和sum作为返回数据集的一部分,c#,linq,linq-to-sql,linq-to-entities,linq-to-objects,C#,Linq,Linq To Sql,Linq To Entities,Linq To Objects,我有一个Linq查询: var result = from game in db.Games join gameevent in db.Events on game.GameId equals gameevent.GameId join birdLife in db.EventBirdCaptures on gameeve
var result = from game in db.Games
join gameevent in db.Events
on game.GameId equals gameevent.GameId
join birdLife in db.EventBirdCaptures
on gameevent.EventId equals birdLife.EventId
select new
{
game.GameId,
game.Name,
gameevent.LocationId, - array of all the location id's based on the game id
birdLife.BirdId - sum of all the birdids based on event id
};
对于最后两个结果,location id和bird id,我想得到location id的id数组和bird id的总和
如何在Linq中实现这一点 我不清楚你在问什么,但如果我了解你想要什么,你可以使用
加入
(群组加入),而不是加入
:
var result = from game in db.Games
join gameevent in db.Events
on game.GameId equals gameevent.GameId into events
from _event in events
join birdlife in db.EventBirdCaptures
on _event.EventId equals birdlife.EventId into birds
select new
{
game.GameId,
game.Name,
locations = events.Select(e => e.LocationId),
birds = birds.Sum(b => b.BirdId)
};
请添加一些输入和预期输出