the owner is a good thing to use, but it doesn't contain the previous
state.
I created some code to get the previous state with reflection.
If you know where to get it without reflection, your code is always
welcome :)


public void OnPostUpdate(PostUpdateEvent evt)
        {
            object[] old = evt.OldState;

            DataObject dataObject = evt.Entity as DataObject;
            if (dataObject != null)
            {
                #region get dirty collections (previous state)

                IList collUpdates =
evt.Session.ActionQueue.GetFieldValue("collectionUpdates") as IList;

                foreach (CollectionUpdateAction item in collUpdates)
                {
                    FieldInfo fi =
item.GetType().BaseType.GetField("persister", BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.IgnoreCase);
                    ICollectionPersister persister = fi.GetValue(item)
as ICollectionPersister;
                    string propertyName =
persister.Role.Split('.').Last();

                    fi =
item.GetType().BaseType.GetField("collection", BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.IgnoreCase);
                    IPersistentCollection coll = fi.GetValue(item) as
IPersistentCollection;

                    if (coll.Owner != evt.Entity) continue;

                    if (coll.IsDirty)
                    {
                        if (Array.IndexOf(evt.Persister.PropertyNames,
propertyName) != -1)
                        {
                            if (coll.StoredSnapshot != null &&
(coll.StoredSnapshot as IList).Count > 0)
                            {
 
old[Array.IndexOf(evt.Persister.PropertyNames, propertyName)] =
coll.StoredSnapshot;
                            }
                            else
                            {
 
old[Array.IndexOf(evt.Persister.PropertyNames, propertyName)] = new
List<object>();
                            }
                        }
                    }
                }
                #endregion

                CreateChangelog(dataObject, old,
evt.Persister.PropertyNames, evt.Session);
            }
        }


On 25 mei, 12:58, John Davidson <[email protected]> wrote:
> I have not used this myself. It may be that there is an incomplete
> implementation or an error in the collection.
>
> What happens when you access the the collection from the
> PostCollectionUpdateEvent.AffectedOwnerOrNull property? What about the
> MemberwiseClone property?
>
> John Davidson
>
>
>
> On Tue, May 25, 2010 at 3:40 AM, Peter Derwa <[email protected]> wrote:
> > Hi John,
> > I looked at it but I didn't really see where i can find the changes.
> > Did you ever look at it yourself? Do you have any Idea where to find
> > it?
>
> > PS: I'm using the SaveOrUpdateCopy since I'm running a WCF service
> > which is closing the session every call, since there are too many
> > users to keep sessions open.
> > the SaveOrUpdate doesn't work, because then the old state does not
> > appear in the PostUpdate EventListener.
>
> > someone also mentioned he was using the session.Refresh, is that also
> > an option?
>
> > grt
>
> > On 21 mei, 12:38, John Davidson <[email protected]> wrote:
> > > I suggest you look at IPostCollectionUpdateEventListener
>
> > > John Davidson
>
> > > On Fri, May 21, 2010 at 4:22 AM, Peter Derwa <[email protected]> wrote:
> > > > Hi,
>
> > > > I'm inspecting the IPostUpdateEventListener and I notice that the
> > > > Oldstate of the Collection of an many to many property isn't correct.
> > > > the Oldstate also contains the current version, not the previous
> > > > version.
>
> > > > Is there a way to find out what the changes are through another
> > > > eventlistener (or if possible of course, i'd like to have it in the
> > > > same one).
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "nhusers" group.
> > > > To post to this group, send email to [email protected].
> > > > To unsubscribe from this group, send email to
> > > > [email protected]<nhusers%[email protected]>
> > <nhusers%[email protected]<nhusers%[email protected]>
>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/nhusers?hl=en.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > > To post to this group, send email to [email protected].
> > > To unsubscribe from this group, send email to
> > [email protected]<nhusers%[email protected]>
> > .
> > > For more options, visit this group athttp://
> > groups.google.com/group/nhusers?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<nhusers%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/nhusers?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to