views:

29

answers:

3
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 };

This isn't working. Basically I want to do the grouping, and then select certain columns, but when I do select new { grp. } I get no intellisense, so I'm obviously doing something wrong.

Any ideas?

+1  A: 

I am not sure but, does the following code work?

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);

EDIT

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, });
Gregoire
That "works" but what I want to be able to do is this: select new { p.ID, GroupName = p.Group.Name, pm.Contribution, p.GameName, }; not sure if that's possible.
Jack Marchetti
pm.Contribution wont work because you´ve grouped by p
alejandrobog
+1  A: 

I think this is what you are looking for

      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 }; 
alejandrobog
+1  A: 
var pools = 
  from p in dc.Pool
  select new
  {
    p.ID,
    GroupName = p.Group.Name,
    Contribution = p.PoolMembers.Sum(pm => pm.Contribution),
    p.GameName
  };
David B