How to eager load objects in a list/collection?

后端 未结 1 1458
慢半拍i
慢半拍i 2021-01-23 12:58

I have the following query:

ObjectB objectBAlias = null;
ObjectC objectCAlias = null;
var query = session.QueryOver();
var results = query
    .Jo         


        
相关标签:
1条回答
  • 2021-01-23 13:37

    I would suggest - do not try that (eager loading of many-to-many). Instead - use built in feature:

    19.1.5. Using batch fetching

    NHibernate can make efficient use of batch fetching, that is, NHibernate can load several uninitialized proxies if one proxy is accessed (or collections. Batch fetching is an optimization of the lazy select fetching strategy. There are two ways you can tune batch fetching: on the class and the collection level.

    To get more details check these:

    • How to Eager Load Associations without duplication in NHibernate?
    • NHibernate Fetch/FetchMany duplication in resultset, how to fix with ToFuture()

    Fetching Collections is a difficult operation. It has many side effects (as you realized, when there are fetched more collections). But even with fetching one collection, we are loading many duplicated rows.

    0 讨论(0)
提交回复
热议问题