Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I tell if a property is dirty using nhibernate?

Tags:

nhibernate

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

like image 952
Chris Avatar asked Feb 12 '09 15:02

Chris


1 Answers

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.

like image 102
joshua.ewer Avatar answered Oct 15 '22 06:10

joshua.ewer