views:

77

answers:

1

This question is a follow on to link text hence the revisited in the title. I raise this as a new question as the accepted answer and comment made under the original question both suggest that the equals keyword used in the join query refers to only value types within the comparison. I believe this is misleading as follows.

Behind the scenes the default equality comparer is used to compare keys using a keyed lookup. The join is implemented in Enumerable.Join and the key can be either a value or a reference.

Included in the other answer was an example using POCOs. I can only assume that as Joins are used in Linq to Sql on primary keys then as these are often simple value types this is where the confusion has arisen.

So does the equals compare values and references to objects?

Have I got this wrong?

+1  A: 

As you seem to state in your question, the equals keyword uses EqualityComparer<T>.Default. Therefore, it will compare the same way that EqualityComparer<T>.Default compares.

If you want to compare by value, you can make implement IEquatable<T>

SLaks
Thanks that confirms my thinking I just could not understand why people were latching onto only the value comparison. I will leave this open for a short while to see if there are any other answers but +1 for now thanks.
Andrew