How to Eager Load Associations without duplication in NHibernate?

后端 未结 2 511
野的像风
野的像风 2020-11-22 08:01

I\'d need to load a list of very large objects with so many children and children of children. what\'s the best approach to take?

I\'m using Oracle 11g database and

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 08:51

    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.

    In general, for collections loading, I would suggest to use the batch processing. This will execute more SQL queries... but not so much, and what is more important, you can do paging on the root list ARNomination.

    See: 19.1.5. Using batch fetching you can find more details.

    You have to mark your collections and/or entities with an attribute batch-szie="25".

    xml:

    
    ...
    

    fluent:

    HasMany(x => x.Contacts)
      ...
      .BatchSize(25)
    

    Please, check few arguments here:

    • NHibernate QueryOver with Fetch resulting multiple sql queries and db hits
    • Is this the right way to eager load child collections in NHibernate
    • https://stackoverflow.com/q/18419988/1679310

提交回复
热议问题