Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use ApplyOriginalValues in Entity Framework 4?

I have used ApplyCurrentValues.

But don't really understand ApplyOriginalValues. How is it different from ApplyCurrentValues? When should I use it?

I have read the documentation. But still confused.

like image 685
Gautam Jain Avatar asked Apr 07 '11 05:04

Gautam Jain


1 Answers

Each entity loaded from the database keeps two sets of values - original (those loaded form DB) and current (those you are modifying). These two sets are hold in ObjectStateEntry. Usually each save is followed by accepting changes which takes current values and writes them to original values. If you know that you made changes to the entity outside of EF (for example by calling stored procedure with common ADO.NET EF) you can force EF to know about those changes without reloading the entity by using ApplyOriginalValues. I think using this method is rather rare. For example I used ApplyOriginalValues in this answer.

like image 154
Ladislav Mrnka Avatar answered Jan 07 '23 23:01

Ladislav Mrnka