views:

95

answers:

1

Here is an example of my entities that I am trying to return with eager loaded collections.

Mixes -> Tracks (collection) -> Tags (collection)

I need to return a paged list of Mixes with eager loaded tracks & tags, without paging it is relativly simple by using the Future<>() function to run multiple queries for the tracks + tags.

Because this data needs to be paged...how can I get all my data back so that NHibernate won't get the N+1 issue when displaying my data.

Paul

+4  A: 
  1. Fetch the Mixes page you want, without any Tracks or Tags.
  2. Fetch all the Tracks (left join Tags) that correspond to the all the Mixes you fetched in the step above (i.e. if you're using HQL, use SetParameterList to pass all the Mixes IDs)

Total: 2 queries.

Mauricio Scheffer
when you say corresponding to the mixes, do you mean by doing a IN() clause from the ID's of my mixes?
Paul Hinett
@Paul Hinett: exactly.
Mauricio Scheffer
thank you...makes sense!
Paul Hinett