When should one avoid using NHibernate's lazy-loading feature?

前端 未结 5 515
礼貌的吻别
礼貌的吻别 2021-01-02 15:32

Most of what I hear about NHibernate\'s lazy-loading, is that it\'s better to use it, than not to use it. It seems like it just makes sense to minimize database access, in

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-02 16:06

    I have seen many performance problems aring from wrong loading behaviour configuration in Hibernate. The situation is quite the same with NHibernate I think. My recommendation is to always use lazy relations and then use eager fetching statemetns in your query - like fetch joins - . This ensures you are not loading to much data and you can avoid to many SQL queries.

    It is easy to make a lazy releation eager by a query. It is nearly impossible the other way round.

提交回复
热议问题