Is it possible to implement undo/redo functions in dbcontext?

Apr 8, 2009 at 7:27 AM
i mean in logic layer, not database rollback.
just like save operation parameter and its inversion operation in stack.
Apr 8, 2009 at 12:17 PM
Nothing is possible but it's very hard. DbEntry don't have the plan to do it. And I don't think it should implement in DbContext.
I suggest to use proxy class for db model if you want implement it in your logic layer.
Apr 8, 2009 at 4:07 PM
To implements your own undo/redo feature is hard for the model who has relations.
But it's easy for simple model.
Just clone the model and store it to a queue will be fine I think.

YourModel YourObj = YourModel.New();
ObjectInfo oi = ObjectInfo.GetInstance(typeof(YourModel));
object clone = oi.CloneObject(YourObj);
Apr 9, 2009 at 12:29 AM
Currently I am using DbObject and handle relations by myself, using Command Pattern to remember any details.

For example,

(1)change A.Name from N1 to N2,
the undo operation should be A.Name=N1
while the redo operation should be A.Name=N2.

(2)delete A which have a relation R with B,
the undo operation should be add A and add R
while the redo operation should be del R and del A,
this one is very hard to implement for the undoed A may have different ID so the add/del R should not base on A.ID but A(how?) or unique identifier like HashCode.

based on this idea, since DbContext handle all the operations, including generate sql statement(is it right?).
Maybe It is easier for it to get the undo/redo information accurately.(that's why i ask this question)

As you said, it's very hard, especially for general operation.
Apr 9, 2009 at 3:29 AM
I think it's more hard than your solution if DbEntry implemented it for general model -- whatever it's in DbContext or not.

For your question about A and A.ID, what I don't understand is why A may have different ID ?
Apr 9, 2009 at 4:04 AM
Because when readd A, it will be considered as a new one.

Oh, Do you mean i should save the A.ID and use it when readd it?
assume there are mutiple editors work at the same time, we can't guarantee that the old ID is still unused.

Anyway, it seems i will implement this function in logic layer.
And i am thinking of using [SoftDelete] and Hash/Guid unique identifier, though no soluntion yet.
Apr 9, 2009 at 11:49 AM
I think you might to use A.ID and A.LockVersion together to get the right record.
And ID means identity, should never be changed.
Apr 9, 2009 at 12:06 PM
Thanks for your suggestion!
Oct 11, 2012 at 12:56 PM

I have written a POC on that purpose. Have a Look -