NHibernate Eager Loading Collections + Paging

那年仲夏 提交于 2019-12-01 03:38:04

问题


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


回答1:


  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.



来源:https://stackoverflow.com/questions/3221482/nhibernate-eager-loading-collections-paging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!