title: Why does List(T).Contains fail to find matches on lists of Entity Framework objects?
body: <p>I've got two lists of "Customer" objects, generated from Entity Framework. I need to compare the two lists to see if there are any differences between them so, naturally, I wrote something like this:</p>
  
  <pre><code>    private static List&lt;Customer&gt; originalList;
  
      public static bool TestForEQ(List&lt;Customer&gt; source, List&lt;Customer&gt; destination)
      {
  
        foreach(Customer cust in originalList) {
          if( !currentList.Contains(cust) )
          {
               return false;
          }
      }
  
   public static void CheckData()
   {
      var ctx = new CustomersEntities();
  
       if(originalList == null)
       {
           originalList = ctx.Customers.ToList&lt;Customer&gt;();
       }
       else
       {
          bool equiv = testForEQ(originalList, ctx.Customers.ToList&lt;Customer&gt;());
          originalList = ctx.Customers.ToList&lt;Customer&gt;()
       } 
   }
  </code></pre>
  
  <p>CheckData is called periodically from a Thread.</p>
  
  <p>So when I stepped through it for the first time, before making any changes to the database between when originalList and currentList were generated, I was surprised to find that the two initial objects in the list were not - according to Contains() - equivalent and that the above code returned false.</p>
  
  <p>I have verified that the basic properties of the two objects (Id, name etc) are equivalent and that no pair of objects from either list are treated as equivalent by Contains(), so ..</p>
  
  <p>1) Can anyone help me find out what property(ies) of two apparently identical data objects are causing Contains() to fail on?</p>
  
  <p>2) Does anyone know of anything on entity framework which would cause two generated entities to not be equivalent if fetched from an untouched data table at different times? Is there a timestamp of some sort? Or are they treated as references?</p>