Why doesnt NHibernate eager fetch my data

心不动则不痛 提交于 2019-12-06 07:54:31

There is a substantial difference between eager fetching and eager loading. Fetching means: putting into the same query. It has several side effects and may break it. Eager loading means forcing NH to load it immediately, not waiting until it is accessed the first time. It is still loaded using additional queries, which leads to the N+1 problem.

NH probably does not eagerly fetch because the property is called ControlDetails, but you pass ControlDetail as argument.

On the other side, this isn't a good way to avoid the N+1 problem. Use batch-size instead. It is fully transparent to the application and reduces the amount of queries by the given factor (values from 5 to 50 make sense, use 10 if you don't know what to use).

One option, you can reduce the select n+1 problem, keep lazy loading and forget about eager loading....

All you need to do is to add one simple attribute batch-size to your XML

<bag name="ControlDetails" batch-size="25" ..>

I also noticed that you have lazy="true" in your mapping, did you try changing to false?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!