Hi Fabio,

That's not exactly what I meant. I want to determine if the property
is dirty before I flush the object/session.
But I found a solution that works for me. Can you tell me if it's save
to do it that way?

My solution:

        public bool IsDirtyProperty(IEntity entity, string
propertyName)
        {
            // Find the className of the Poco object
            string className = entity.GetType().FullName;

            if (entity is INHibernateProxy)
            {
                className = entity.GetType().BaseType.FullName;
            }

            ISessionImplementor session =
_Session.GetSessionImplementation();

            IPersistenceContext persistenceContext =
session.PersistenceContext;

            IEntityPersister persister =
session.Factory.GetEntityPersister(className);

            EntityKey keyToLoad = new EntityKey(entity.ObjectIdentity,
persister, session.EntityMode);

            object obj = session.GetEntityUsingInterceptor(keyToLoad);

            EntityEntry oldEntry = session.PersistenceContext.GetEntry
(obj);

            object[] oldState = oldEntry.LoadedState;
            object[] currentState = persister.GetPropertyValues(obj,
session.EntityMode);
            int[] dirtyProps = persister.FindDirty(currentState,
oldState, obj, session);

            // Find the index of the propertyName
            int index = Array.IndexOf(persister.PropertyNames,
propertyName);

            // Check if the index is in the dirtyProps array
            bool isDirty = Array.IndexOf(dirtyProps, index) != -1;

            return isDirty;
        }

Best regards,
Harm.

On 7 okt, 02:24, Fabio Maulo <[email protected]> wrote:
> http://tinyurl.com/ydhgsgl
> 2009/10/6 Harm Neervens <[email protected]>
>
>
>
> > Is it possible to find out if a property of an entity is changed/
> > dirty?
> > I have an entity Customer. When it's saved by the application/GUI, I
> > want to know if the Address property is dirty. If so, I have to write
> > a record to a log table.
>
> --
> Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
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