Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate Eager Loading Collections + Paging

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

like image 758
Paul Hinett Avatar asked Jul 11 '10 01:07

Paul Hinett


1 Answers

  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.

like image 185
Mauricio Scheffer Avatar answered Oct 18 '22 12:10

Mauricio Scheffer