OK, what I am trying to do is fetch two datasets from their respective databases and join them using a Linq query, formed by the Join extension method. The Linq query did work before, but after some refactoring (in other parts of the code) it does not anymore. I really fail to see the difference.
I have expanded the KeySelectors and the ResultSelector to be able to put breakpoints in them. The two enumerables (localSeq and remoteSeq) work fine, they got the right number of elements etc. The elements of both sequences are formatted as Object(). The KeySelectors (implemented by the function CompositeJoinKeySelector) also seems to work. What this function is supposed to do is select the right fields from every element, so that the .Join method knows how to check for equality. It seems to be this step (check for equality) that fails.
When I step through the code, the linq query loops through both the datasets and executes the KeySelector. This seems to return the intended values. Afterwards, however, it does not break in the ResultSelector. It seems to me that this means it never got to process the result, because he did not find matching “rows”. This is quite weird, because I stepped through the execution and both KeySelectors return a two-dimensional Object array and matching entries certainly exist.
Is there any way to see this (presumably) nested loops process and see where the equality comparison fails?
Dim LocalSeq As IEnumerable(Of Object()) = From locRow As Object() In LocalArray
Dim RemoteSeq As IEnumerable(Of Object()) = From remRow As Object() In RemoteArray
Dim joinSeq As IEnumerable(Of Object()) = LocalSeq.Join(Of Object(), Object, Object())(RemoteSeq, _
Function(locRow As Object())
Dim locRes As Object() = CompositeJoinKeySelector(locRow, LocalKeyList)
Return locRes
End Function, _
Function(remRow As Object())
Dim remRes As Object() = CompositeJoinKeySelector(remRow, RemoteKeyList)
Return remRes
End Function, _
Function(locRow As Object(), remRow As Object())
Dim joinRes As Object() = JoinRowArrays(locRow, remRow, FinalJoinSelectColumnList)
Return joinRes
End Function)
Return joinSeq.ToArray()
Okay, it appears that the comparison failed because a reference-compare was used by default. So, I solved the problem by implementing an IEqualityComparer.