Lazy loading means that you don't bring the associations when an
entity is loaded. But when you accessing the association (thru
properties), nHibernates goes and fetches if for you. In order for the
lazy loading to work, the session should be open. If it's not open
then you'd get that error. Also if you are using NH version 1.2 then
you don't need to set lazy=true as all associations are lazy by
default.
Example
ISession session = SessionFactory.OpenSession()
Master master = session.Load<Master>();//only master is loaded withoud
any associations
Children children = master.Children(); // lazily fetch children.
session.Close();
the children are fetched successfully as the session was open but if
you do this
ISession session = SessionFactory.OpenSession()
Master master = session.Load<Master>();//only master is loaded withoud
any associations
session.Close();
Children children = master.Children(); // lazily fetch children.
then you will get the error as the session is closed.
Hope that helps.
On Apr 25, 11:29 am, FrenchC <cres...@gmail.com> wrote:
> Hi all,
> first of all, I'm a newbe to NH... Then: my problem is that I have to
> entities: MupRuns and Mappings. The first one is the master entity and
> the second one contains the children of each of the first one... When
> I get access to the first one, if I set lazy="true" when I try to
> dislpay the children of each of the master it return an error saying
> that there is no session active...
> To be precise consider that in the hbm.xml of the master the child is
> setted as bag and in the master class the children list is setted as
> an IList<Mappings>. Both these 2 entities aren't to be persisted on
> the db...
> Of course if I leave both 2 in lazy="false" all works fine, but the
> performances decrease impressively...
> Is there someone that can explain clearly and with some example how to
> set a correct lazyloading?
> Thx in advance
> Francesco