Here is the problem:

   1. public IList<Incident> Filter()
   2. {
   3.         ISessionFactoryHolder sessionHolder = ActiveRecordMediator.
   GetSessionFactoryHolder();
   4.         ISession session = sessionHolder.CreateSession(
typeof<http://www.google.com/search?q=typeof+msdn.microsoft.com>
   ( Incident ) );
   5.         try
   6.         {
   7.                 ...       }
   8.         finally
   9.         {
   10.                 sessionHolder.ReleaseSession( session );
   11.         }
   12. }


By the time you access the lazy properties, the session you created manually
is already disposed. Since the lazy proxies use that session, they cannot
access the DB anymore. Use a SessionScope instead. That scope should not be
used within the filter method, but created and destroyed along with the
form, window, request or whatever. SessionScopes are part of the
infrastructure, not of the business logic.

2009/8/6 bdaniel7 <[email protected]>

>
> all are virtual.
> here is the snippet: http://dblendea.pastebin.com/f1d9caf00
>
> i tried to run within a SessionScope, however i got a no session/proxy
> exception.
>
> On Aug 5, 11:40 pm, Markus Zywitza <[email protected]> wrote:
> > Are all properties virtual? Do you use a SessionScope?
> >
> > -Markus
> >
> > 2009/8/5 bdaniel7 <[email protected]>
>  >
> >
> >
> > > Hi,
> > > I have an Incident, which is [Lazy].
> > > Incident has an Address, which is also lazy.
> >
> > > But sometimes, when I load a collection of Incident, and the filter
> > > doesn't have an Address field,
> > > and i try to check some address i get this LazyInitializationException
> > > from NH.
> >
> > > If i remove the [Lazy] from Address all goes well.
> >
> > > Now, is it possible to force loading a lazy property/entity?
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" 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/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to