Suppose I have the following class:
public class Test{
public string Length { get; set; }
public string Width { get; set; }
public string Height { get; set; }
public int Count { get; set; }
public string Label { get; set; }
}
And I would like to find items that have the same value for length and label and counting how many there are for each. So far my code looks like:
var dups = testlist.GroupBy(i => new { i.Length, i.Label })
.Where(g => g.Count() >= 1)
.Select(g => new { Length = g.Key.Length, Label = g.Key.Label,
Count = g.Count() });
But the problem is, the objects in var no longer have the width or height property (they don't exist in g.Key). Is there anyway to find duplicates based on two properties while saving other properties in the result?
Whereclause is redundant - if there're no items with a given label and height, there won't be a group for them anyway.)