Click here to Skip to main content
14,168,858 members
Rate this:
Please Sign up or sign in to vote.
See more:
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:

Updated 22-Mar-18 22:33pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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!
Member 13586256 23-Mar-18 4:40am
But it works fine if I use this save function without a parameter(Options).
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.190518.1 | Last Updated 23 Mar 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100