sql - JoinAlias vs. Joinquery over differences toward Rowcount -
from understand, joinalias supposed functionally similar joinquery in ways return object. ie joinalias returns outer iqueryover , joinqueryover returns 1 join object. in following example:
query.left.joinalias(() => eventalias.children, () => childalias); query.where(() => childalias.name.isin(searchcriteria.selectednames.toarray()));
the rowcount 29.
but here:
query.left.joinqueryover(s => s.children).where(restrictions.in(projections.property<child>(x => x.name), searchcriteria.selectednames.toarray()));
query.rowcount(); returns 18.
the 18 want. there 18 entries on db.
i did research on distinctrootentityresulttransformer() brings count 14 after alias, still not correct.
on high level i'd gain better understanding happening, on immediate level i'd know if need use alias.
thanks
--- edit --- should left join, becuase count can 0, , want parent items. noted in answer, when run exact same filter same join (left) results identical. however, when no 1 searches, still create alias, , without filtering @ getting 29.
the first issue solved andrew. second cartesian product.
check this: nhibernate fetch/fetchmany duplication in resultset, how fix tofuture()
when join root children - result set gets multiplied. there many rows have children. not many have roots.
my suggestion be, use batch-fetching load collections ex-post, query root entity. filter children, use sub-queries...
check how use batch fetching:
- documentation - 19.1.5. using batch fetching
- how eager load associations without duplication in nhibernate?
how use subquery filter root:
- how queryover in nhibernate on child collection
- nhibernate - many many query using junction/joiner table
how distinct root entity works?
Comments
Post a Comment