aggregate - NHibernate - Eager loading grouped object when aggregating -
i have following code aggregating auction statistics statistics table , returning auction summed counts (there may multiple rows in statistics table per auction...)
var stats = _session.queryover<auctionstatistic>() .select( projections.group<auctionstatistic>(s => s.auction), projections.sum<auctionstatistic>(s => s.bidcount), projections.sum<auctionstatistic>(s => s.viewcount), projections.sum<auctionstatistic>(s => s.searchcount) ) .orderby(projections.sum<auctionstatistic>(s => s.applicationcount)).desc .fetch(x => x.auction).eager .take(take) .list<object[]>();
the query seems work fine - except auction returned evaluated lazily, causing select n+1 scenario. can provide suggestions how field can evaluated eagerly?
thanks in advance
jp
the brute force way (similar sub-select):
_session.queryover<auction>().whererestrictionon(a => a.id).isin(stats.selectmany(s => s).oftype<auction>().select(a => a.id).toarray());
Comments
Post a Comment