I have a question because I can not resolve it on my own, I've seen
the Nhibernate Documentation and the Nhibernate in Action
but I can not find it still.

The question is on the Lazy Collection, for example I make the lazy
property to true (lazy="true") on collection's be it one-to-many or
many-to-many or many-to-one.

The thing is when I retrieve an entity like Person the Collection
Articles in it is not initialized yet because of the lazy="true", and
for the moment I don't need the Articles, but after a while I'm going
to need the Articles and now I can not retrieve the Articles unless
the session is open, but I apply the Unit of Work Pattern and close
the session immediately.

The question is How am I going to retrieve the Articles?   How to
reattach the deattached Person from the session and call
NhibernateUtil.Initialize(person.Articles)

i tryed like this:

public void Initialize(Person p)
{
  using(ISession session=NhibernateDataProvider.GetSession())
  {
        NhibernateUtil.Initialize(p.Articles);
  }
}

This code above did not functioned. It throws an Exception when I call
foreach(Article item in p.Articles)  { ... }
Failed to Load Lazly Collection ...

the only solution is reload the Person and call
NhibernateUtil.Initialize(p.Article) in the unit of work, now it works
but it seems to me not natural reloading the Person again when I have
it.

Do you now a solution to this problem?
Should I leave the session open?
Because it is very expensive to load all Collection at once.

Thank you very much for your contribution

Visar

P.S I'm developing a Desktop Application by the way.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to