I have a 1-1 relationship between Orders and Contact. i.e. Contact.OrderId references Orders and is also a PK.
So I have an existing Order and I add a new Contact to it like so…
order.Contact = new Contact() { EmailAddress = "hello" };
context.Orders.Attach(order);
context.SaveChanges();
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.
So what am I doing wrong?
Just generate your child entity, set its
OrderIdReferenceproperty and you should be good to go.