score:6

Accepted answer

you want a groupjoin rather than a join. the difference is that rather than having all of the related items flattened into a list of pairs, it groups all of the joined items into a sequence:

var query = from p in context.person
            join g in context.group
            on p.personid equals g.personid into groups
            select new
            {
                name = p.name,
                age  = p.age,
                groupids = groups.select(g => g.groupid),
            };

using query syntax the use of the into keyword in conjunction with a join will result in a groupjoin instead of a join.

score:2

i coded on so's editor. if i understand right you want person's groups. otherwise correct me please.

 var p = from p in context.person         
     select new
     {
         name = p.name,
         age  = p.age,
         groups = from g in context.group
                  where p.personid == g.personid
                  select g.groupid
     };

Related Query

More Query from same tag