I have this objects:
notes:[
{ user: {
name: "A",
group:{
id:1,
name:"Group 1"
}
},
{ user: {
name: "B",
group:{
id:1,
name:"Group 1"
}
}]
and I need to group it by group.. so I tried this:
foreach (IGrouping<Group, Note> item in notes.GroupBy(n => n.User.Group))
{
var groupName = item.Key.Name;
foreach (var note in item)
{
//
}
}
But I got a problem because grouping is not working(I think it’s because it uses references to group a complex type).
If I change n.User.Group by n.User.GroupId it works, but if I do it I can’t get the group name.
You need to override Equals and GetHashCode in Group class. R# generates this kind of code for it: