NHibernate渴望加载集合+分页 [英] NHibernate Eager Loading Collections + Paging

查看:69
本文介绍了NHibernate渴望加载集合+分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我尝试通过急切加载的集合返回实体的示例.

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

混合物 ->曲目(收藏) ->标签(集合)

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

我需要返回带有急切加载的曲目的混音的分页列表&标签,而无需分页,通过使用Future<>()函数对track +标签运行多个查询相对简单.

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.

因为需要分页数据...我该如何取回所有数据,以便NHibernate在显示数据时不会出现N + 1问题.

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.

保罗

推荐答案

  1. 获取所需的混音"页面,没有任何曲目或标签.
  2. 获取与您在上述步骤中获取的所有Mix相对应的所有轨道(左连接标记)(即,如果您使用的是HQL,请使用
  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)

总计:2个查询.

这篇关于NHibernate渴望加载集合+分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆