-->
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: How to stop the children from being loaded in some cases
PostPosted: Sat Sep 17, 2005 6:20 am 
Im a beginner using nhibernate and so far I really like what i see. I have one problem however and I've looked high and low for an answer but I suspect my problem is a result of not understanding the new terminology very well. Anyway heres my scenario. I have Country entity with a (one-to-many) with a cities entity, which has a relationship (one-to-many) with a schools enitity. I used the following code:

IList countries = session.CreateCriteria(typeof(Country)).AddOrder(NHibernate.Expression.Order.Asc("countryname")).List();


This is great, I can see in the debugger the cities of a given country, and the schools of a given city. Problem is in some cases I only want a list of countries and not the children. Now I realise I can edit my mapping file so that it doesn't return the children but in some cases I will need it. Say for eg I just want one country and its related children. So basically im thinking i need the ability in my code to switch it on/off. Problem is I have no idea. I've heard of lazy loading but dont much about it, in fact I dont even know if this is the fix. Ive also thought about overriding my properties in the class files but i cant inherit the class file to do this as I need to inherit from System.Web.UI.UserControl.

Any help?

And in some cases I many want one country and its children.


Top
  
 
 Post subject:
PostPosted: Sat Sep 17, 2005 10:31 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, lazy loading is the fix. Set lazy="true" for the collection, and it won't be loaded until it's accessed.


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.