This project is read-only.

How to get entity/record values before update.

Topics: Troubleshooting, Writing modules
Jul 31, 2013 at 4:11 PM
Edited Jul 31, 2013 at 4: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 8: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 10: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 10: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 11:01 PM
Edited Jul 31, 2013 at 11: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.
Aug 1, 2013 at 12:15 AM
Why don't you use the built-in versioning feature?