tags:

views:

1521

answers:

3

Hello,

Does anyone know if it is possible to tell if a specific property on an object is dirty (i.e. the property is different to the one stored on the DB) using NHibernate?

The background to this question is that I will have an object with a (relatively) large number of properties on it. I need to be able to pass a parameter (string) to a function that will determine if that specific property has changed during the lifetime of the page.

If I need to I can create a copy of the object and use reflection at the end of the page lifecycle to check the value, but I am reluctant to do this. It would be great if NHibernate could simply tell me if a property was dirty.

Thanks

+1  A: 

That is not currently available through the nHibernate (or Hibnernate, AFAIK) API. You could write something like this yourself by storing the state of the objects when they're loaded into session, then compare them.

NOTE: I haven't seen this for myself, but, if you haven't locked into an ORM choice, you should look at Subsonic. A lot of the dirty status is tracked within the objects themselves, and you'd be able to determine if a particular property is dirty.

joshua.ewer
A: 

I think this is serious lack of NHibernate. I know that NHibernate holds informations about changed state of object but I don't know why it is so difficult to retrieve this informations.

I asked Ayende for this but He gives me weasel words, nothing more.

dario-g
NHibernate != Ayende. Use the google group if you have any questions: http://groups.google.com/group/nhusers
Mauricio Scheffer
+10  A: 

Check out this method: http://nhforge.org/wikis/howtonh/finding-dirty-properties-in-nhibernate.aspx

cbp