Note this question is similar this one except I’m not working with linq-to-sql, so the “let” is not usable.
Basically I have a select of the type
... .Select(c => new SampleClass { Id = c.Location.Name, Name = c.Location.Name }).Distinct().ToList()
which used to work when I just had
... .Select(c => c.Location.Name).Distinct().ToList()
How would I make a distinct call on one of the items within the SampleClass?
You can group items by the key, and then select what item from the group you want to use as value. I use
FirstOrDefaultas an example: