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
|
Hi guys, We recently encountered a bug in our code, and I could use a hand.
We have 2 objects, A, which contains a set of B. Essentially, A is an observer to a collection of B objects. Whenever the subject B is modified, a transient field in A is also updated. We then have an OnSaving override in A which allows us to serialize all the changes made in A during the unit of work, and persist the database field in the xml format we hand back to users. This worked in version 2.2 because transient fields caused the EntityState to be marked as modified. In 3, this has been fixed according to the changelog.
http://www.mindscape.co.nz/products/lightspeed/changelog.aspx
Currently, the only way I can get the entity onsaving to fire is to increment then immediately decrement a counter which is persisted in the entity. This is a bit of a hack to say the least, how can I explicity mark the entity as dirty so that the OnSaving event fires and the persisted fields are updated via the serialization? I obviously can't do EntityState = EntityState.Modified with my entity since I can't access the entity state.
Thanks guys, Todd |
|
|
Our normal recommendation would be to update the persistent field as you go, rather than waiting until OnSaving and updating it from a transient field at that point. Is that feasible for you, or are you expecting to make so many changes to the XML that you need to make them on an infoset for performance reasons (to avoid large numbers of serialisations)? |
|
|
Hey Todd :-) Not sure it this will help or not but I've done this a couple of times. I imagine that your updating the transient field which is serializable and this is being stored in the db somewhere, however, at this point in time its not being saved because its not looking like something has changed. To get the OnSaving to fire set the string field to null through the setter of the string field you are saving in to whenever you update the transient field - this will cause the entity to move into a modified state and then will get populated correctly when you serialize it during the OnSaving event. Hope that is of some help/makes sense/is what your are talking about - this solves having some dummy field to push the entity to a modified state :-) Cheers, James |
|
|
thanks guys, Setting that to null resolves my issues. I'd prefer to avoid serialization until the end, otherwise that's a lot of I/O processing that will simply be discarded. Now on to the next question, we didn't intially catch this because we didn't have any unit tests that reflected this serialization across multiple units of work. I've added those now, and my test breaks unless searilization occurs properly. Take it easy James, good to hear from you!
|
|
|
Ignore the poor grammer, had a copy paste error! |
|