How do you map a HasOne relationship with nHibernate Fluent mapping and avoid N+1? -


i have 2 tables atable , aatable both have shared primary key - atable.akey , aatable.akey represent one-to-one relationship. fluent mapping have hasone relationship defined within fluent atablemapping, of works fine. have noticed querying atable generates 2nd query (n+1) child table aatable. understanding hasone eager loads default, , had assumed part of query atable, may have wrong?

i have researched various solutions including using .not.lazyload().fetch.join(), propertyref, foreignkey cannot seem resolve n+1 either eager loaded 1 query, or lazy loaded , can fetch child queries.

has had issues or have example know work no n+1? grateful advice.

you have 2 options:

  1. not.lazyload() disables possibility provide lazy loaded related entity , enforce nhb provide corresponding subselect within original query
  2. use component mapping both entities point same table. better approach once decided fetch both entities together, generated queries hit 1 table - not 2 within first option. better performance.

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -