0
votes

When attaching the model to the context, the following InvalidOperationException is thrown:

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.

My model has a business entity that can have many branch entities.

When posting back values to controller, and trying to attach the business object received from the HTML form, it throws the exception above.

1

1 Answers

0
votes

The issue was that there is both a reference in the business to all the branches, and additionally a reference to the business from within the branch, which in case, must be included in the form so the reference property (BusinessId) is posted back.

After including the business ID in the branch form, issue was solved:

@Html.HiddenFor(brand => brand.BusinessId)