var groups = from p in dc.Pool
join pm in dc.PoolMembers on p.ID equals pm.PoolID
group p by p.Group into grp
select new { grp.ID };
这不起作用。基本上我想进行分组,然后选择某些列,但是当我select new { grp. }
时,我没有智能感知,所以我显然做错了。
有什么想法吗?
答案 0 :(得分:1)
我不确定但是,以下代码是否有效?
var groups = from p in dc.Pool
join pm in dc.PoolMembers on p.ID equals pm.PoolID
group p by p.Group into grp
select grp.Select(g=> g.ID);
修改
var groups = from p in dc.Pool
join pm in dc.PoolMembers on p.ID equals pm.PoolID
group p by p.Group into grp
select grp.Select(g=> new{
Id = g.Id,
GroupName = grp.Key.Name,
Contribution = pm.Contribution,
GameName = p.GameName, });
答案 1 :(得分:1)
我认为这就是你要找的东西
var groups = from p in dc.Pool
join pm in dc.PoolMembers on p.ID equals pm.PoolID
group p by p.Group into grp
select new { grp.Key.ID, GroupName = grp.Key.Group.Name, grp.Key.GameName };
答案 2 :(得分:1)
var pools =
from p in dc.Pool
select new
{
p.ID,
GroupName = p.Group.Name,
Contribution = p.PoolMembers.Sum(pm => pm.Contribution),
p.GameName
};