Using .Select and .Where in a single LINQ statement

In order for Enumerable.Distinct to work for your type, you can implement IEquatable<T> and provide suitable definitions for Equals and GetHashCode, otherwise it will use the default implementation: comparing for reference equality (assuming that you are using a reference type). From the manual: The Distinct(IEnumerable) method returns an unordered sequence that contains no duplicate values. … Read more

LINQ’s Distinct() on a particular property

EDIT: This is now part of MoreLINQ. What you need is a “distinct-by” effectively. I don’t believe it’s part of LINQ as it stands, although it’s fairly easy to write: So to find the distinct values using just the Id property, you could use: And to use multiple properties, you can use anonymous types, which implement equality appropriately: … Read more