List<Foo> fooList = new List<Foo>();
fooList.Add(new Foo(){
Id = 1,
Bar = 1,
Blah = 1
});
fooList.Add(new Foo(){
Id = 1,
Bar = 2,
Blah = 1
});
fooList.Add(new Foo(){
Id = 2,
Bar = 1,
Blah = 2
});
If I group my fooList by the Id property, all properties except Bar are equal to each other for each group. I noticed that there is a GroupMy lambda method, but is there any way to group the lists by Id, and make the Bar property a list of all the Bars for each id?
Because right now i have a lot of redundant data on each row. Please let me know if you want me to elaborate the problem.
Use the GroupBy extension that lets you determine the element selector:
Or if you want
Barto be an explicit property:Though I find that a little hard to read.