LINQ to Objects .Distinct() not pulling distinct objects
- by Anthony Potts
I have two ways that I am doing a fuzzy search for a customer. One is by an abbreviated name and the other is by the customers full name. When I take these two and then union them together (which I have read several places should remove distinct values) I get duplicates. Thinking that all I need to do is then call the .Distinct() method on this I also still get Duplicates. Do I need to implement some compare functionality in my customer object?
My code:
Dim shortNameMatch As List(Of ICustomer) = CustomerLibrary.GetCustomersByShortName(term)
Dim custNameMatch As List(Of ICustomer) = CustomerLibrary.GetCustomersByCustName(term)
Dim allMatch = (From a In (From s In shortNameMatch Select s).Union(From c In custNameMatch Select c) Select a).Distinct()