Nhibernate / MVC: Working with lazy downloadable collections in a view

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?

+5
source share
3 answers

(-, ) - ; , ( ) dto .

dtos, , , , , dtos, . , Automapper , .

open-session-in-view - , , - .

+3

. , , , .

  • ISession, View, , ...
  • , EOL: , nhibernate lazyless, , multihql/ ..

: , , , . . , HQL, fetch

+1

I do not think that in the first approach there is nothing wrong, and it will be easiest to implement.

Request Session is a well-known session management template for NHibernate.

0
source

All Articles