lazy loading in the view is good way kill performance. it can lead to
select n+1 errors that are difficult to track down. i would recommend
option 2. build a view model independent of the domain objects and map
the required data from the domain to the view. it's easier to catch n
+1 and your view model is specific to the screen making maintenance
easier over the life of the project.

On Sep 30, 11:38 am, Oskar Berggren <[email protected]> wrote:
> At least either of:
> a) Keep session open until application_endrequest() or similar.
> Additional benefit of removing this crosscutting concern from each
> action method.
> b) Construct a view model in the action, where everything that the
> view will need is already loaded before the session is closed and the
> action method finishes. In this case I believe you can use an
> ActionFilter to get the session handling out of the actual action
> method code.
>
> /Oskar
>
> 2010/9/30 lszk <[email protected]>:
>
> > Hi all.
> > In action I taken some data from db. Now in view I want to take value
> > from one field which is referenced from other table with lazyload, by
> > I get this error: Could not initialize proxy - no Session
>
> > I wonder what I can do with it.
>
> > public ActionResult Index()
> >        {
> >            using (NHUnitOfWork.Start())
> >            {
> >                var news = articlesRepository.News(0, 20);
> >                return View(news);
> >            }
> >        }
>
> > <%= Html.ActionLink(Html.Encode(Model.Author.Login), "zyx", "xyz") %>
>
> >  public ArticleMap()
> >        {
> >            References(x =>
> > x.Author).Not.Nullable().LazyLoad().Column("Author").Cascade.SaveUpdate();
> >         //...
> >        }
>
> >    public class Article : EntityBase<int>
> >    {
> >        public virtual User Author { get; set; }
> >         //...
> >    }
>
> > --
> > 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 
> > athttp://groups.google.com/group/nhusers?hl=en.

-- 
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.

Reply via email to