Tuesday, 18 November 2014

Entity Framework Exception - A referential integrity constraint violation occurred


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.

1 comment:

  1. Your method of explaining the whole thing in this post is in fact pleasant, every one be capable of effortlessly be aware of it, Thanks a lot. You just made it so easy to understand, made me want to learn more about it!

    Optimized360 is the No.1 Healthcare Website Design Firm in The USA.

    ReplyDelete