Last post Aug 04, 2014 10:35 AM by ThatsIT
Aug 02, 2014 06:39 AM|ThatsIT|LINK
I am trying to use intersect to find overlapping dates in a schedule.
Where programEvents and otherEvents are lists of SceduleEvent objects
If Not programEvents.Intersect(otherEvents, New BO.Models.ConflictingScheduleEventsComparer).Count.Equals(0) Then
test = False
When debugging I see that programEvents has 9 scheduleEvent objects and otherEvents has 32. I would expect the comparere to be called 288 times(9*32) but is only called 9 times.
Why is this?
Public Class ConflictingScheduleEventsComparer
Implements IEqualityComparer(Of ScheduleEvent)
Public Overloads Function Equals(x As ScheduleEvent, y As ScheduleEvent) As Boolean Implements IEqualityComparer(Of ScheduleEvent).Equals
If Object.ReferenceEquals(x, y) Then Return True
Return (x.Start < y.End AndAlso x.End > y.Start) OrElse (y.Start < x.End AndAlso y.End > x.Start)
Public Overloads Function GetHashCode(obj As ScheduleEvent) As Integer Implements IEqualityComparer(Of ScheduleEvent).GetHashCode
If obj Is Nothing Then
Throw New ArgumentNullException("obj")
Dim hashProductCodeStart As Integer = obj.Start.GetHashCode
Dim hashProductCodeEnd As Integer = obj.End.GetHashCode
Return hashProductCodeStart Xor hashProductCodeEnd
Aug 04, 2014 02:11 AM|Kevin Shen - MSFT|LINK
Thanks for your post.
For your question is not related with Data Access (ADO.net,Entity Framework,LINQ to sql ,Nhibnerate), ,i suggest that you can post your question to the link below,you will get a better suggestion for you:
Aug 04, 2014 10:35 AM|ThatsIT|LINK
My problem was a misunderstanding on the implementation of the GetHashCode method.
"Implementations are required to ensure that if the
Equals method returns true for two objects
x and y, then the value returned by the
GetHashCode method for x must equal the value returned for