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.
|