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 view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/QoUUHxwpxY0J.
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