title: Entity Framework: A referential integrity constraint violation on many to many relationship
body: <p>Hey I have an application with a bunch of inproc caching and entity framework. When I want to write an update to an entity I reattach the cached copy. I track all things I've attached in the life cycle of the context so I don't try to attach them twice.</p>
  
  <p>I have an error occurring on attach (very rarely in most cases this works fine and is really fast) which says the following:</p>
  
  <blockquote>
    <p>A referential integrity constraint violation occurred: The property
    values that define the referential constraints are not consistent
    between principal and dependent objects in the relationship.</p>
  </blockquote>
  
  <p>I've taken a really careful look at the entity which looks normal. I think this issue is due to the attachment/detachment of a foreign key when fixups runs. </p>
  
  <p>Is there a good way to get any more info on this error or can it occur for reasons other than that the entity was in a state which EF wasnt expecting?</p>
  
  <p>EDIT:
  DB Diagram (note i'm using codefirst I just used the EDMX tool to make the diagram, I've also chopped a bunch of regular properties off the model for simplicity)</p>
  
  <p><img src="https://i.stack.imgur.com/44dlz.png" alt="enter image description here"></p>