LINQ to Objects .Distinct() not pulling distinct objects

Posted by Anthony Potts on Stack Overflow See other posts from Stack Overflow or by Anthony Potts
Published on 2010-05-19T21:33:26Z Indexed on 2010/05/19 21:40 UTC
Read the original article Hit count: 375

Filed under:
|
|

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()

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about distinct