开发者

Bound FetchMany in Linq to NHibernate

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

W开发者_JAVA百科ARN:

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

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


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).

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

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

So insted of doing

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)

which produces a SELECT TOP (5) query

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜