The answer

http://fabiomaulo.blogspot.com/2009/03/ensuring-updates-on-flush.html

2009/4/2 [email protected] <[email protected]>

>
> Hi,
>
> I'm looking for a way to prevent NHibernate from automatically dirty
> checking entities and then automatically updating them.
>
> What I want to achieve is to require session.Update(myObj) to be
> called on an object for it to be saved (but associated objects should
> also be updated provided there are appropriate cascade rules
> configured)




>
>
> Detaching the objects is not a viable solution because of lazy loading
> relationships, and I don't think setting flushmode to never is the
> right solution either.
>
> Here's what I'm doing, in case anyone has a better idea...
>
> I have a web application (asp.net mvc) and I establish a session(nhib
> session) on begin_request and commit it on end_request.
>
> Take an entity update request for example: A user edits the values in
> a form and posts it to my application. My app gets the relevant
> entity, changes the values then validates the object to make sure it
> is in a valid business state. if validation passes, i can call
> session.update and return. However if validation fails, i need to
> return the user to the edit screen with validation errors. My problem
> is that even though im not calling session.update in this failed
> validation case, my object is still saved by the auto dirty checking!
>
> I'd really prefer to turn this behaviour off, I don't want things to
> be happening automatically, I want things to be saved only when I
> explicitly tell them to be.
>
> I've read that I can override the default dirty check listener so that
> all objects are considered not-dirty and therefore not saved. Is this
> an appropriate solution? This is where I am stuck. I've tried creating
> my own IDirtyCheckEventListener and registering it in my NHib config,
> however (unless I did something wrong) OnDirtyCheck() is never called :
> (
>
> Can someone please give me some pointers on how to disable this
> behaviour and achieve what I want?
>
> Thanks
>
> Andrew
>
> >
>


-- 
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