Should this thread move to nhusers...? Seems overloaded to have this conversation here...
http://groups.google.com/group/nhusers On Mon, Mar 23, 2009 at 12:56 PM, Fabio Maulo <[email protected]> wrote: > 2009/3/23 [email protected] <[email protected]> > >> >> I'm developing a web application, and I'm using a UnitOfWork to create >> me a session/tx on begin_request and it flushes/commits on >> end_request. > > > You have implemented your own UoW or you are simply using the NH-session ? > > >> On an edit screen for one of my persisted objects, I get the object >> from NH, set the properties with the POSTed data from the edit form, >> then validate the object to make sure no business rules are violated. >> In pseudo code: >> >> var person12 = Session.Linq<Person>().Query().Where(x => x.Id = 12); >> >> person12.Age = int.parse(form["Age"]); >> >> if(person12.Age >= 18) >> Session.Update(person12); >> else >> throw new ValidationException("You must be at least 18"); >> >> >> The problem is that if the validation fails, the person object is >> still saved when the transaction is committed on end_request. > > > Sure ? Why you are calling session.Update before validate the entity ? > Or why you are not using a validation in a NH-Event listener ? > > >> What should I do about this? >> >> It seems very strange to me that dirty objects should get saved >> without me telling the session to update it. Can I just turn this >> behaviour off? If so, how? It seems strange that there is a >> Session.Update(object) method, if you cant turn it off. > > > The UoW (nh-session) is dirty when at least one of his object is dirty. > You can turn-off the auto-flush and manage the flush by your self. > > The other option is turn-off the dirty-check overriding the default > listener. > > -- > Fabio Maulo > -- Steve Bohlen [email protected] http://blog.unhandled-exceptions.com http://twitter.com/sbohlen
