Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I am using WPF using MVVM model with entity framework but i am getting this error while changing the value or foreign key column.I am using SaveOptions.AcceptAllChangesAfterSave
option to save the change because or speed issue.Please help me.

A referential integrity constraint violation occurred: The property value(s) of 'EventStatus.ID' on one end of a relationship do not match the property value(s) of 'Event.EventStatusID' on the other end.

What I have tried:

_objectContext.SaveChanges(SaveOptions.AcceptAllChangesAfterSave)
Posted
Updated 22-Mar-18 22:33pm

1 solution

We can't solve this for you: it's got too much to do with your data, and how you are manipulating it.

What's happened is that a value is left in a table, or inserted into a table which depends on other table information, or which other tables depend on.

For example, if you have an Invoices table, and an InvoiceLines table, then the InvoiceLines table will have a InvoiceID column which refers back to the Invoices table and ties all the data together. If you delete a row from Invoices and leave the ID's in InvoiceLines then that causes a referential integrity failure, because there are lines who no longer have an invoice. Similarly, if you ad lines to InvoiceLines without creating a matching Invoice row first, you have the same problem.

But we have no access to your data, or to your user input - so we can't do anything to work out why this occurred!

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Comments
Member 13586256 23-Mar-18 4:40am    
But it works fine if I use this save function without a parameter(Options).
_objectContext.SaveChanges()
OriginalGriff 23-Mar-18 4:41am    
Doesn't matter - we still can't look at it for you! :laugh:
Member 13586256 23-Mar-18 4:43am    
Ok thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900