I am currently using an attribute-based approach to control an nhibernate session, which means that the session is open for the duration of the Action method, but closes after the control is passed to the view.
This seems like good practice to me, but I ran into problems with lazy downloadable collections. (This is complicated by the fact that some collections seem to be lazy loading, even if they have Not.LazyLoad () set in the current mapping).
As I can see, my options are:
- Change my ISession Management Strategy and Save Session in View
- It is better to use ViewModels (I currently do not use them everywhere).
- Bright loading of all collections that cause problems (maybe unloaded) (runaway problem does not stand up)
1 seems a bit wrong - but it might be the “easiest” solution. 2 is probably the right way, but in some cases, ViewModels seem a little redundant, and I hate introducing more classes to deal with this problem. 3 seems a bit dirty fix.
What do you think?
source
share