views:

58

answers:

1

I'm working on a legacy system that is using the enterprise library validation block to add a broken rule when an object is not valid. Then the user is returned a message based on this error and told the object was not updated.

The only issue is that now I'm using NHibernate to persist these objects -NHProf shows an update to the object when I commit the session. This is because the object has been modified I assume and the ORM is simply doing its job.

My question is this - what would be the best way to check for these broken rules before I commit the session? Or should I not use Enterprise library and switch to something NHibernate friendly?

Update

I came across this event listener class for the NHibernate Validator Event Listener - my final implementation was very similar

+1  A: 

I'm not familiar with the enterprise validation block, but can't you write an interceptor or something like that which can be used to determine whether the object can be saved or not, based on the information you have regarding the broken rules ?

You can also choose not to use the automatic dirty checking of NHibernate.
This means that you'll have to call 'Save' yourself on an object you have modified in order to get that object saved. You can get this functionality via NH Addins

Frederik Gheysels
I like the event listener option you mentioned - i'll verify the entity based on interface and then check to see if it has any broken rules - and finally if it does i will simply rollback the transaction. I prefer this over asking to "save" each time - it's nice to have that functionality w/out having to think about it
Toran Billups