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!
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 aJoinAlias
(differences of the two have been discussed in other SO questions)So insted of doing
which produces the warning in the question, we do
which produces a
SELECT TOP (5)
query