nhibernate collection set mapping to avoid n+1 select and duplicate rows with fetch join -


i have object table , object aliases table.

the aliases set collection of strings:

object.aliases 

if map collection this:

<class name="object" table="object" lazy="false">     ...     properties...     ...     <set name="aliases" table="aliases" inverse="true" lazy="false" fetch="join" >       <key column="objectid" />       <element column="name" type="string"/>     </set>     ... </class> 

then

session.createcriteria(typeof (t)).list<t>(); 

from base repository fetches objects, returns duplicates each alias. why? how can rid of duplicate objects in list?

thank time.

edit: updated mappings... that's mappings. aliases doesn't have it's own class it's set of strings needs loaded iset<string> object.aliases

i confused this, too, when started using nhibernate. that's how works. because mapping includes fetch="join", it's using sql join between parent table , child table, parent data repeated each child. rather filter out instances of parent, collection 1 object per row in query. need indicate want distinct objects. using icriteria syntax, can add transformers.distinctrootentity query.

see get distinct result set nhibernate using criteria api?, , link mentions within.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -