Skip to main content

Posts

Showing posts from July, 2014

EF error: OriginalValues cannot be used for entities in the Added state

Problem : OriginalValues cannot be used for entities in the Added state I was working on a repository and came across an interesting, cryptic error that resulted from a fairly simple operation: Saving the changes. Without getting into code details (which are  irrelevant to the point), the call to the following statement failed: Context.SaveChanges(); The error message read: OriginalValues cannot be used for entities in the Added state When saving new entries to a SQL Server database using the Entity Framework, I came across the following exception error: OriginalValues cannot be used for entities in the Added state There may be a number of reasons why the exception was raised but I found that in my case I had to check the data I was trying to save to make sure that values were specified for all the fields and that the fields were in the ranges required by the SQL Server database. Here is a list of the checks I had to implement before writing the data to the database us