EntityLoader ignores subselect fetching option

Description

Problem

EntityLoader doesn't override the property Loader.IsSubselectLoadingEnabled. That means that NHibernate won't generate subselects even if they were configured in the mapping. This can lead to performance problems (N+1 problem).

Remark: The property Loader.IsSubselectLoadingEnabled is processed in Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, bool returnProxies, IResultTransformer forcedResultTransformer).

Possible solution

Override Loader.IsSubselectLoadingEnabled in EntityLoader by calling Loader.HasSubselectLoadableCollections(). This is already done by CriteriaLoader, QueryLoader and CollectionLoader.

I don't know if this could produce any unwanted side-effects.

Example (Fluent NHibernate)

If the Abc instances are loaded by NHibernate using batch fetching, there won't be a single SELECT with subselect for the AbcArraySize instances. Instead there will be one SELECT for each ArraySize instance.

Workaround (well, not really)

One can add a call to BatchSize in the above HasMany mapping. There still won't be a subselect as intended but at least the generated SELECTs for AbcArraySize will use batch fetching.

Environment

Windows 7.
Target platform of the project using NHibernate: .NET 4.0

Assignee

Unassigned

Reporter

visubesy

Labels

None

Components

Affects versions

Priority

Major
Configure