Entity Framework Exception - A referential integrity constraint violation occurred. When you get this type of the exception it just simply means that you need to match Ids of the related entities. Exception: A referential integrity constraint violation occurred: The property value(s) of 'Image.Id' on one end of a relationship do not match the property value(s) of 'BaseEntity.SomeImageId' on the other end. A typical mistake that cause this exception is: baseEntity.SomeImageId (type of Image) and Image.Id Does not match. So if you change the new added related entity to the negative Ids ( see the related blog post ), then you also need to modify the parent end of the Id (one end of the relationship as Entity Framework expression goes). So that both "ends" have the same Id value.
Peter Stegnar's software development reflections on software development, cloud computing and quants. Some random thoughts are also on the line.