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:
not.lazyload()
disables possibility provide lazy loaded related entity , enforce nhb provide correspondingsubselect
within original query- 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
Post a Comment