ttajic
9/8/2017 - 1:08 PM

LINQ GroupBy

var newList = list.GroupBy(x => new {x.School, x.Friend, x.FavoriteColor})
                    .Select(y => new ConsolidatedChild()
                                        {
                                            FavoriteColor = y.Key.FavoriteColor,
                                            Friend = y.Key.Friend,
                                            School = y.Key.School,
                                            Children = y.ToList()
                                        }
                    );
                    
var results = persons.GroupBy(
    p => p.PersonId, 
    p => p.car,
    (key, g) => new { PersonId = key, Cars = g.ToList() });