0

So, here is the situation -

  • I insert an item in the database calling the AddtoObject() and then call SaveChanges().
  • Then, I call a stored procedure to update the currently inserted record.
  • Then, I call the Save changes() again.
  • The database when I query it has the correct updated value, but the entity framework context does not have the updated values..the first time..whenever I refresh the page it gets the value..but the first time it never gets the updated values.

So has anyone faced a similar issue anytime ? What am I doing wrong here ?

1 Answer 1

6

The problem is that the EF does not know what your stored procedure is doing, how could it? That work is done at the SQL Server. So after your stored procedure executes, you need to ask EF to update that (and other related) instance by issuing a Refresh() call:

context.Refresh(RefreshMode.StoreWins, myObject);

The StoreWins tells the framework to overwrite values in the instance with values from the database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.