Click here to Skip to main content
15,893,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Additional information: The changes to the database were committed successfully, but an error occurred while updating the object context. The ObjectContext might be in an inconsistent state. Inner exception message: Saving or accepting changes failed because more than one entity of type 'Project.Models.CertiStaging; have the same primary key value. Ensure that explicitly set primary key values are unique. Ensure that database-generated primary keys are configured correctly in the database and in the Entity Framework model. Use the Entity Designer for Database First/Model First configuration. Use the 'HasDatabaseGeneratedOption" fluent API or 'DatabaseGeneratedAttribute' for Code First configuration.

What I have tried:

I have two database tables named Certi and CertiStaging, both has same primary key. I don't want to remove that primary key nor want to alter anything in my models. How can I get rid of that run time EF Error?
Posted
Updated 10-Aug-16 17:34pm
v2

1 solution

Sounds like you are trying to save data that conflicts the rules of the primary key uniqueness. Have a look at the data you are saving and see if there is a record of the same primary key values you are try to save. If so, the data is invalid so or you need to create a more prescriptive primary key to ensure record uniqueness or change the data you are saving.
 
Share this answer
 
Comments
Priyanshu Patel 10-Aug-16 17:03pm    
Sounds Perfect. But how can i create a more prescriptive primary key to ensure record uniqueness or change the data I am saving.
RossMW 10-Aug-16 17:05pm    
On the database tables. Not your application.

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