everything in transaction similiar enough to what you suggested
above...
//ismodelvalid
//try
//begin trans
//do a
//do b
//let NH know about changes to a
//let NH know about change to b
//committ
//Catch
//Rollback
//throw up to controller
//finally
//any cleanup
I am using MVC, but we decide to go explicity as opposed to managing
transactions in centralised being_request or simillar.
Cheers.
On Oct 31, 12:56 pm, Jason Meckley <[email protected]> wrote:
> ouch, that is horrendous use of NH and the duplicated exception code is
> just terrible. I highly recommend searching the web for alternative NH
> strategies.
>
> with MVC frameworks you can typically reduce the NH footprint within the
> controller action to 1 call. the session and transaction scope are
> encapsulated else where
>
> begin request - open session
> begin action - begin transaction
> action - load entity(s)
> end action - if error rollback, else commit
> end request - dispose session
>
> actions can then look like this
>
> public Result GetEntity(long id)
> {
> var entity = session.Get<Entity>(id);
> return entity.ToViewModel();
>
> }
>
> public Result ModifyEntity(ViewModel view)
> {
> var entity = session.Get<Entity>(view.Id);
> entity.Property = view.Value;
> ...
> //no need to explicitly call session.Save or the like
> return RedirectToAnotherAction();
>
> }
>
> public Result RemoveEntity(ViewModel view)
> {
> var entity = session.Get<Entity>(view.Id);
> var child = session.Load<Child>(view.ChildId);
> entity.Remove(child);
> ...
> //no need to explicitly call session.Delete
> return RedirectToAnotherAction();
>
>
>
>
>
>
>
> }
--
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.