Possible use case for filters. http://nhforge.org/doc/nh/en/index.html#filters
-Carlos Practice makes perfect, but if no one is perfect, why practice? > Date: Tue, 11 Aug 2009 11:34:16 -0700 > Subject: [nhusers] NH is loading a lazy loaded child collection when i'm not > itterating over it! > From: [email protected] > To: [email protected] > > > hi guys, > > i've got strange problem that i'm hoping is just down to my > inexperience with NH... > > i asked this question on stackoverflow: > http://stackoverflow.com/questions/1244995/partially-populate-child-collection-with-nhibernate > and learnt that it is by design that NH lazy loads the entire child > collection when you itterate over it, regardless of a supplied > restriction (in this case i only want child objects with a certain > date). > > so the recomendation was to just load the parent object, then > separately query for the filtered children i wanted, then associate > them. > > so i've tried that, and it looks to be a winner, except, what ever i > do, NH keeps hitting the Db and fully populating the child collection, > even though its lazy loaded, and i'm not iterating over it. > > very annoying. > > what i want to do is something like the following: > > var post = session.CreateCriteria<BlogPost>() > .Add(Restrictions.Eq("Id", 1)) > .UniqueResult<BlogPost>(); > > var comments = session.CreateCriteria<Comment>() > .Add(Restrictions.Eq("BlogPostId", 1)) > .Add(Restrictions.Eq("DatePosted", new DateTime(2009, 8, > 1))) > .List<Comment>(); > > post.Comments = comments; > > but running this bit of code with Sql Profilier running shows that 3 > queries get sent to the database, the first one is to get the single > post (good) when the fist statement gets executed, and when the second > statement gets executed, we get two queries sent to the Db, the first > of these is to get the filtered list of comments (good!), but then > another is sent to get the entire list of comments (bad!). > > the example i've got here is not the domain my project is in. in the > real domain the child collection is MASSIVE, and would never be > queried without a filter on the date, so i REALLY dont want the whole > lot coming back! > > has anyone got any ideas? > > cheers, > chris. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
