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
|
Hello, Assuming I have an Entity that has a collection of other entities (one to many). When the child entity saves, I want the parent entity to be saved as well. Is there a way for me to force that. For example, if the child entity changes, I want to increment the version field of the parent property and save that.
Thanks! |
|
|
This isn't directly possible: you could override OnSaving in the child and use that to update the parent, but LightSpeed makes no guarantees about whether changes made during OnSaving will get picked up during the current save (in fact, in this case I am pretty sure it wouldn't, because parents get saved before children), so you would need to do a second save to flush the new changes. A better approach is probably to override the child's OnPropertyChanged, and use that to update the parent. (To avoid multiple version updates, the parent could hold a transient boolean flag saying "have I already updated my version in response to a child change," and increment its version only if this flag wasn't already set. You would then override the parent's OnSaving to reset the flag.) Basically you need to get the change into the parent before calling SaveChanges(), because if the parent isn't dirty at the beginning of the save cycle, it won't get saved, whereas if it is dirty, it will be saved automatically. This reflects that the save is at the unit of work level rather than the entity level. |
|
|
Thank you. That makes sense.
|
|