2

我使用支持fetchmany我的一些疑問和NHibernate的探查給了我以下錯誤:綁定支持fetchmany NHibernate的

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

我想這是因爲獲取綁定。有針對這個的解決方法嗎?

回答

1

出現此問題是因爲使用FetchMany會將整個結果集帶到內存,然後接受指定的子集(效率低下且潛在危險)。

顯然,在使用FetchMany時,在獲取子集之前無法限制子集。

的解決方案是使用一個JoinQueryOverJoinAlias(兩者的差異已經在其他SO問題討論)

所以insted的做

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

其產生警告中的問題的我們做

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

其產生的SELECT TOP (5)查詢