NHibernate 热切加载集合 + 分页 [英] NHibernate Eager Loading Collections + Paging

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

问题描述

这是我尝试使用预先加载的集合返回的实体示例.

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

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

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

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

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. 获取与您在上述步骤中获取的所有混音相对应的所有曲目(左连接标签)(即,如果您使用的是 HQL,请使用 SetParameterList 传递所有 Mixes ID)
  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天全站免登陆