How to get entity/record values before update.

Topics: Troubleshooting, Writing modules
Jul 31, 2013 at 3:11 PM
Edited Jul 31, 2013 at 3:11 PM
Hey. I'm getting enity via the following code:
myEntity = myRecordRepository.Get(myId);
Then I change some properties etc, whatever.

When it comes time to update changes, I'd like to get entity values BEFORE update. When I try
old = myRecordRepository.Get(myEntity.Id);
old contains the same values as myEntity (updated one). How can I get old values?
Jul 31, 2013 at 7:08 PM
Copy what you need to hold onto into local variables. old here is only a reference to the same object, not a clone.
Jul 31, 2013 at 9:02 PM
I simply can't. myEntity is returned via function, so someone can change it's properties outside my "manager" class, and then call update. So, the scenario is that I want create function like this:
public void Update(Entity someEntity)
     var old = /* get somehow entity before update */
So can't store properties as variables, becaue a don't know what entity user call to update.
Any ideas?
Jul 31, 2013 at 9:51 PM
Then you'll have to make a deep clone, which sounds overkill. What is the scenario that requires this?
Jul 31, 2013 at 10:01 PM
Edited Jul 31, 2013 at 10:01 PM
Let's say I've two tables: Entity and EntityArchive. I want to store all versions of record in the EntityArchive table. So, like I've written, I want to get entity with old values, insert it into EntityArchive and then update row in Entity table.
Jul 31, 2013 at 11:15 PM
Why don't you use the built-in versioning feature?