These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Lazy Loading an Object Collection
PostPosted: Mon Sep 17, 2007 12:13 pm 
Newbie

Joined: Sun May 29, 2005 3:55 pm
Posts: 13
Hi,

I am using Lazy Loading to fill up a collection of an object. I have Exam class which has a IList of Questions. Now, I want that when I retrieve the Exam by Id I should get all the Questions of that exam. I can get this to work by simply iterating through the collection but it is not a good technique.

I can use the following approach to get all the questions of the exam.

using (ISession session = sessionFactory.OpenSession())
{
exam = session.Get<Exam>(id);

foreach(Question q in exam.Questions) { }
}

I just need to iterate over the questions and then it will be populated. How can I make it better since the above code does not make any sense?

Off course, I can say <bag name="Questions" lazy="false" but then what if I want to retrieve 100 Exams but I don't want to retrieve all the questions of every single exam.

Any ideas?


Top
 Profile  
 
 Post subject: RE:
PostPosted: Mon Sep 17, 2007 12:39 pm 
Newbie

Joined: Sun May 29, 2005 3:55 pm
Posts: 13
Actually, I got the answer from Ayende's blog:

http://www.ayende.com/Blog/archive/7627.aspx


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.