SetMaxResults and eager fetch of collections don't mix.
This is one approach to collection eager loading:
http://ayende.com/Blog/archive/2010/01/16/eagerly-loading-entity-associations-efficiently-with-nhibernate.aspx
<http://ayende.com/Blog/archive/2010/01/16/eagerly-loading-entity-associations-efficiently-with-nhibernate.aspx>In
your case you can't use Future, but you can still to it in 2 queries instead
of N+1.

   Diego


On Wed, Jun 9, 2010 at 15:43, curlyfro <[email protected]> wrote:

> if i don't add SetMaxResult i get back everything in a single query.
> if i set FetchMode.Join & SetMaxResult then i get Tracks.
> if i set FetchMode.Select & SetMaxResult then i get Albums but i get
> Select N + 1 not a single query.
>
> how do i get 10 Albums in a single query?
>
> On Jun 9, 2:27 pm, "Jim Case" <[email protected]> wrote:
> > use a fetch mode of join instead of eager.
> >
> >
> >
> >
> >
> >
> >
> > -----Original Message-----
> > From: [email protected] [mailto:[email protected]] On
> Behalf
> >
> > Of curlyfro
> > Sent: Wednesday, June 09, 2010 2:26 PM
> > To: nhusers
> > Subject: [nhusers] Problem using SetFetchMode in NHibernate
> >
> > i've got this method:
> >
> >         public IEnumerable<Album> GetAllAlbumsWithTracks()
> >         {
> >             var albums = Session.CreateCriteria(typeof(Album))
> >                 .SetFetchMode("Tracks", FetchMode.Eager)
> >                 .SetResultTransformer(new
> > DistinctRootEntityResultTransformer()).Future<Album>();
> >
> >             return albums;
> >         }
> >
> > but if i .SetMaxResult(10), i get back 10 Tracks.  how do i get back
> > 10 Albums?
> >
> > --
> > 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]<nhusers%[email protected]>
> .
> > For more options, visit this group athttp://
> groups.google.com/group/nhusers?hl=en.
> >
> > No virus found in this incoming message.
> > Checked by AVG -www.avg.com
> > Version: 9.0.819 / Virus Database: 271.1.1/2897 - Release Date: 06/09/10
> > 02:35:00
>
> --
> 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]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>

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

Reply via email to