将 Linq 中的 FetchMany 绑定到 NHibernate [英] Bound FetchMany in Linq to NHibernate

查看:23
本文介绍了将 Linq 中的 FetchMany 绑定到 NHibernate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 FetchMany 进行一些查询,而 NHibernate 分析器给了我以下错误:

I am using FetchMany for some of my queries and the NHibernate profiler gives me the following error:

警告:
第一个结果/最大结果用集合提取指定;在内存中申请!

WARN:
firstResult/maxResults specified with collection fetch; applying in memory!

我猜这是因为 fetch 是未绑定的.有解决办法吗?

I guess this is because the fetch is unbound. Is there a solution to this?

推荐答案

出现这个问题是因为使用 FetchMany 会将整个结果集带入内存,然后取指定的子集(效率低下且有潜在危险).

This problem arises because using FetchMany will bring the whole result set to memory and then Take the specified subset (something inefficient and potentially dangerous).

使用 FetchMany 时,显然无法在获取之前限制子集.

Apparently there is no way to limit the subset before fetching when using FetchMany.

解决方案是使用 JoinQueryOverJoinAlias (两者的区别已在其他 SO 问题中讨论过)

The solution is to use either a JoinQueryOver or a JoinAlias (differences of the two have been discussed in other SO questions)

很想这么做

Session.QueryOver<Product>().FetchMany(p=>p.Images).Take(5)

在问题中产生警告,我们这样做

which produces the warning in the question, we do

Image image = null;
Session.QueryOver<Product>().Left.JoinQueryOver(x => x.Images, () => image).Take(5)

产生 SELECT TOP (5) 查询

这篇关于将 Linq 中的 FetchMany 绑定到 NHibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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