score:3
Accepted answer
First, you don't need to implement the IEqualityComparer(Of T)
interface; you would normally implement that in another class if you wanted to provide multiple types of equality for the same class.
Second, you'll need to override the GetHashCode
and Equals(Object)
methods:
Partial Public Class CustomerData
Implements IEquatable(Of CustomerData)
Public Override Function GetHashCode() As Integer
Return CustomerID.GetHashCode()
End Function
Public Override Function Equals(ByVal obj As Object)
Return Equals(TryCast(obj, CustomerData))
End Function
Public Overloads Function Equals(other As CustomerData) As Boolean Implements IEquatable(Of ToolData.CustomerData).Equals
If other Is Nothing Then
Return False
Else
Return Me.CustomerID = other.CustomerID
End If
End Function
...
Here's a blog post which explains why: http://blogs.msdn.com/b/jaredpar/archive/2009/01/15/if-you-implement-iequatable-t-you-still-must-override-object-s-equals-and-gethashcode.aspx
Source: stackoverflow.com
Related Articles
- LINQ Source Code Available
- .NET 4 Code Contracts: "requires unproven: source != null"
- creating Linq to sqlite dbml from DbLinq source code
- IEquatable(Of T)/IEqualityComparer(Of T) Not Being Called
- Is there a way to re-use a LINQ statement, but alter the property and method being called on that property?
- source code for LINQ 101 samples
- IEnumerable Where filtering occuring without actually being called
- List or Array of String Contain specific word in Html Source Code
- c# Linq or code to extract groups from a single list of source data
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Value cannot be null. Parameter name: source
- Linq code to select one item
- C# - code to order by a property using the property name as a string
- How do I find the text within a div in the source of a web page using C#
- Roslyn failed to compile code
- Limit Number of Results being returned in a List from Linq
- Entity-framework code is slow when using Include() many times
- The data source does not support server-side data paging
- How are people unit testing code that uses Linq to SQL
- Entity Framework, Code First and Full Text Search
- What does this C# code with an "arrow" mean and how is it called?
- How to resolve Value cannot be null. Parameter name: source in linq?
- The source contains no DataRows
- Could not find an implementation of the query pattern for source type 'System.Data.Entity.DbSet'
- How to count the number of code lines in a C# solution, without comments and empty lines, and other redundant stuff, etc?
- LINQ's Func<bool> is only called once?
- Is there an IEnumerable implementation that only iterates over it's source (e.g. LINQ) once?
- Entity Framework 6 Code First Custom Functions
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Select distinct rows from two datatables using LINQ
- How does the Select() method return anonymous types?
- How do you perform a left outer join using linq extension methods
- System.InvalidOperationException: The LINQ expression 'GroupByShaperExpression:
- Using Linq to Entities and havign a NOT IN clause
- Using a type in linq
- EF - cannot convert from System.Linq.IQueryable to System.Data.Objects.ObjectQuery
- Select values for a range of given indexes using Linq C#
- How to simplify complicated conditional clauses when using LINQ to SQL
- Mapping $filter from oData parameter to linq Where
- Having Single and SingleOrDefault to throw a more succinct exception
- How to find if time is within A set of range?
- How to apply distinct to linq query in c#?
- Proper Linq Query for objects with many to many relation ship generated with code first entity framework
- Using union inside a foreach loop for linq to sql
- How can I filter nested items of IQueryable<T>?
- C# LINQ Check sum of columns in the same query
- How can I select XElements where Attribute ... (LINQ2XML)
- find complete object in list of objects
- Need to close Debugger and restart before saved data can be read