title: Should DDD entities compare by reference or by ID?
body: <p>When I started using DDD, I created <code>Equals()</code> methods in my entities that compared the ID of the entity. So two entity objects with the same ID would be considered equal.</p>
  
  <p>At some point I thought about that and found that two entities in different states should not be considered equal, even when they describe the same thing (i.e. have the same ID). So now I use reference equality for my entities.</p>
  
  <p>I then stumbled over <a href="https://stackoverflow.com/a/2363183/219187">this answer</a> by Mark Seemann, where he writes</p>
  
  <blockquote>
    <p>Entities are equal if their IDs equal each other.</p>
  </blockquote>
  
  <p>Now, of course, I'd like to know which approach is better. </p>
  
  <p>Edit: Note that the question <strong>is not</strong> whether having two instances of the same entity at the same time is a good idea. I'm aware that in most situations it is probably not.</p>