How does Linq Except Compare results
<p>How does Except determine if 2 values are the same</p>

<p>I have the following code</p>

<pre><code>var removes = collection.Except(values, comparer).ToList();
var adds = values.Except( collection, comparer).ToList();
foreach (var item in removes)
{
    collection.Remove(item);
}
foreach (var item in adds)
{
    collection.Add(item);
}
</code></pre>

<p>however items that the comparer say are equal are included in the except lists, so to see what is happening I put a break point in the Equals function and its not being called, only the GetHashCode() function</p>

<p>So what criteria is being used to compare the items, is it only if the hashes are different that it calls the equality function?</p>

<p>Edit:
the comparer Class and compared class are</p>

<pre><code>public class Lookup
{
    public static readonly IEqualityComparer&lt;Lookup&gt; DefaultComparer = new EqualityComparer();
    private class EqualityComparer : IEqualityComparer&lt;Lookup&gt;
    {
        public bool Equals(Lookup x, Lookup y)
        {
            if (x == null)
                return y == null;
            else if (y == null)
                return false;
            else
                return x.ID == y.ID
                    &amp;&amp; x.Category == y.Category
                    &amp;&amp; x.DisplayText == y.DisplayText
                    &amp;&amp; MetaData.CollectionComparer.Equals(x.MetaData, y.MetaData);
        }

        public int GetHashCode(Lookup obj)
        {
            var rtn = new { obj.ID, obj.Category, obj.DisplayText, obj.MetaData }.GetHashCode();

            return rtn;
        }
    }
    [DataMember]
    public int ID { get; set; }
    [DataMember]
    public LookupType Category { get; set; }
    [DataMember]
    public string DisplayText { get; set; }
    [DataMember]
    public MetaData[] MetaData { get; set; }
}
</code></pre>