Skip to main content
Home Forums Silverlight Programming WCF RIA Services Undo changes
12 replies. Latest Post by Leopqdt on November 6, 2009.
(0)
Leopqdt
Member
15 points
37 Posts
11-03-2009 11:46 AM |
Hi Guys
Well, my truble now is how to undo changes made in my entity objects. What i mean is,suppose i've got from DB an object (Person) which has 3 properties: Name, Gender and BirthDay, then i sought thr Person with ID = 3 and shown on the screen. The user made changes in this object and repented, then clicked Cancel Button.
I wish that every changes made in that object were undone, but without having to go back on the DB and refresh the context.
ps. The example shown above is just a simple exemple, in my real scenario, my object Person has a lot of relations with other objects which should undo their changes too.
Any Idea? Yhanks!
11-03-2009 12:04 PM |
Well my friends,
i figured out the solution for this.i'm using a DomainDataSource then if Cancel button were clicked, i just do it:
dds.RejectChanges();
Works Fine!
Thanks!
meidianto
605 points
130 Posts
11-03-2009 12:10 PM |
[deleted]
11-03-2009 12:35 PM |
hello meidianto
what did you mean with [removed]?
ColinBlair
Contributor
6741 points
1,318 Posts
11-03-2009 2:28 PM |
This board lets you edit your posts. He deleted the text of his original post (I am guessing you posted your found answer while he was still typing and submitting) and put in the removed to show that he deleted his original text.
11-03-2009 4:31 PM |
hey colin
yes i understud now, nothing to do with my answer then... Just removed post!?
thanks!
11-03-2009 5:00 PM |
hello
it's me again, i reopened this post because even i manage to solve my question, i believe that have something else.I just want reset the EntityState of my object for it do nor replicate changes that i've done. If i make some changes in it and i press cancel button i wish undo that changes, as i said before the method RejectChanges of DomaidDataSourcesolve my problem, but it only fires when i close oll of my windows, and i wish it fires when i clicked cancel button of mythird window open, i mean, now i don't need to cancel all changes of all object, just one in particular.
was me clear?
11-03-2009 5:20 PM |
Every RIA Services entity implements the IRevertibleChangeTracking interface. All you have to do is cast your entity to IRevertibleChangeTracking and call RejectChanges. RejectChanges does not work for new or deleted entities.
11-03-2009 10:15 PM |
Rigth, it's good, but in case of i need to do it in new entities, i mean, when the user clicks the button New to createa new Person, i create a new instance of Person which gonna be filled by user informations inputed. But anytime theuser could wish cancel some information already inputed and cancel it, and what we have here, a new entity thatwas modified and needed to be undone.
What could i do in these cases?
11-04-2009 11:57 AM |
For new entities you just need to remove it from the EntityList yourself.
11-06-2009 10:57 AM |
Ok, Colin, we are almost there,i thought do it too, but tell me how could i differentiate an entity from other, i mean,suppose i have an object Person which has an EntityCollection TypePerson ok!?Then i create a new object Person what mean that my EntityCollection is null. I fillthe object Person and create a new object TypePerson and add it into EntityCollection.Now i have my new entity Person and an EntityCollection with an object TypePerson.Ok, i decided insert other object TypePerson into EntityCollection, now, i have two newo bjectsinside EntityCollection. To be a New Entity, these has not id to differentiate each other, buti decided remove one from EntityCollection, how could i know which entity remove, if it has no idor something that i could identify?
Do you know a solutuion?
11-06-2009 11:12 AM |
What kind of key are you using? Identity, GUID, or something else? I use GUIDs myself so this isn't a problem as I always have a key. You could go ahead and set a key (I used to start at -1 and count down from there) for temporary use. When you save it will be automatically replaced with the real ID.
11-06-2009 11:18 AM |
Right, i understud, i'm using Entity Framework and i don't know how it deals it.I believe that is something internal of the Framework, i don't know if i could changethese process by myself.
is it possible?