This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
The scenario I have a parent child relationship (one to many) in entities Element and ChildElement(s). When I make a changes on the Element level only, BeginEdit, EndEdit and CancelEdit works as expected. The part that doesn't work is the moment a change is made to the ChildElments collection. When the ElementChilds are changed and lets say the Element was also changed, I do a SaveChanges(). This posts correctly to the underlying DB. Now when I change someting on the Element ( after SaveChanges()) and then CancelEdit - it Cancels correctly on the Element (to the state after SaveChanges()) but the problem is that it cancels the ChildElements to the state prior to the SaveChanges(). But if a second session is opened then both the Element and ChildElements display correct and according to the data in the underlying DB. What is going wrong here and how can this be fixed? Thank you |
|
|
Can you elaborate a little on exactly when you are calling BeginEdit, EndEdit and CancelEdit for each entity? It sounds like you are doing a BeginEdit before the SaveChanges, and not committing (EndEdit) the pending edits. CancelEdit will take you back to the last BeginEdit (though it does sound like there's a bit of an inconsistency in the way it handles parents and children). You may need an EndEdit before the SaveChanges and a new BeginEdit after the SaveChanges. |
|
|
Hi Ivan Thanks for the quick response. To tell the truth I have tried quite a few combinations and I can't determine a specific pattern on what is going on. My understanding is as follows: 1 - SaveChanges post to the database CancelEdit will cancel all changes since the last beginedit BeginEdit will mark a new point to rollback to in the event CancelEdit is called. I am using WPF and databing within a MVVM pattern I display the list of Elements in a DataGrid and bind this to a property called SelectedElementList The SaveChanges was moved around and I have tried it both before and after the BeginEdit but mostly after the EndEdit call. The Edit calls are only done on the parent (main) entity (Element) and not on all the ChildElements. And as I have explained earlier the canceledit then do cancel changes on the child entities but not in the manner expected (see my initial post). A function that would be really helpful here is to call an "Undo" and sync the entity to what is in the database. I have tried a few other work arounds but this becomes a bit to complex and almost impossible as I tried to reinstate the original entity state without causing undesired results and entries into the db. The intention is also not to creatre a new record in the DB - as this indicates a new element instead of keeping the original element. Thank you Hermanus Smalman |
|
|
When you do a BeginEdit on a parent entity, that automatically does a BeginEdit on any associated EntityCollections as well. This in turn calls BeginEdit on all the children into the collection. When you do a CancelEdit on a parent entity, it does a CancelEdit on any associated EntityCollections, which rolls back any inserts or removals, and calls CancelEdit on each member of the collection. However, it appears that when you do an EndEdit on an entity, it does *not* call EndEdit on the associated EntityCollections. This seems like a bug to me but I will raise it with the rest of the team. So I think what is happening is that you are doing a BeginEdit-EndEdit-BeginEdit-CancelEdit cycle on the parents: the CancelEdit rolls the parents back to the second BeginEdit, but it rolls the children back to the first BeginEdit (because they never got the EndEdit and therefore ignored the second BeginEdit). The workaround is, when you call EndEdit on the parent, call EndEdit on the child collection(s) too: myElement.EndEdit(); To avoid polluting your application code, you can encapsulate this by overriding Element.EndEdit: public override void EndEdit() { I'll let you know what we plan to do about this when I've talked to the rest of the team. |
|
|
Thank you, Ivan I will build the work around and let you know. Regards Hermanus Smalman |
|
|
Hi Ivan This seem to work 100%. If I do encounter other related problems on this I will log on the same thread. Just one observation. If I call a EndEdit on the individual entities i.e. public overried void EndEdit() { base.EndEdit(); foreach (ChildElement child in this.ChildElements) { child.EndEdit(); { }
This also did not work as expected. Thank you for excellent support. Hermanus Smalman |
|
|
Ivan, hello. I ran into this problem as well. We will try the workaround, but is there a more pleasing workaround available now? Thanks, Peter |
|
|
Hello Peter, No, this is still the recommended workaround. |
|