我有这个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 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
};
对于最后两个结果,位置ID和小鸟ID,我想获取位置ID和小鸟ID的总和的ID数组。
如何在Linq中实现?
我不清楚您要问的是什么,但是如果我了解您想要的内容,则可以使用join-into
(组加入)代替join
:
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)
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句