Why can’t NHibernate open a new connection (or session) if it has to lazy-load associations?First, we think it’s a better solution to fully initialize all required
objects for a specific use case using eager fetching (this approach is
less vulnerable to the n+1 selects problem). Furthermore, opening
new database connections (and ad hoc database transactions!)
implicitly and transparently to the developer exposes the application
to transaction isolation issues. When do you close the session and
end the ad hoc transaction—after each lazy association is loaded?
We strongly prefer transactions to be clearly and explicitly
demarcated by the application developer. If you want to enable lazy
fetching for a detached instance, you can use Lock() to attach it to a
new session.
这段话看得不是很懂,哪位高手帮我解释一下,用自己的理解也行。

解决方案 »

  1.   

    为什么不能NHibernate打开一个新连接(或)如果有lazy-load社团?
      
      首先,我们认为这是一个更好的解决办法来充分的初始化所有必需的
      对象为某一特定的用例使用这种方法(渴望获取
      那么容易受到了n + 1选择问题)。另外,
      新的数据库连接(和特设数据库事务!)
      隐和透明的开发应用。暴露
      对事务隔离问题。当你关闭对话和吗
      最后transaction-after特设的每一个懒惰的关联上吗?
      我们极力要清晰和明确的交易
      由应用程序开发者划定。如果你想使懒惰
      取一个超然的情况下,你可以使用锁()将一个
      新的会话。