NHibernate. Distinct parent child fetching
Posted
by Andrew Kalashnikov
on Stack Overflow
See other posts from Stack Overflow
or by Andrew Kalashnikov
Published on 2010-06-01T03:38:06Z
Indexed on
2010/06/01
3:43 UTC
Read the original article
Hit count: 617
nhibernate
|criteria
Hello. I've got common NH mapping;
<class name="Order, SummaryOrder.Core" table='order'>
<id name="Id" unsaved-value="0" type="int">
<column name="id" not-null="true"/>
<generator class="native"/>
</id>
<many-to-one name="Client" class="SummaryOrderClient, SummaryOrder.Core" column="summary_order_client_id"
cascade="none"/>
<many-to-one name="Provider" class="SummaryOrderClient, SummaryOrder.Core" column="summary_order_provider_id"
cascade="none"/>
<set name="Items" cascade="all">
<key column="order_id"/>
<one-to-many class="OrderItem, Clients.Core" />
</set>
</class>
Want get list by this criteria
ICriteria criteria = NHibernateStateLessSession.CreateCriteria(typeof(SummaryOrder.Core.Domains.Order)); ;
criteria.Add(Restrictions.Or
(Restrictions.Eq(String.Format("{0}.Id", SummaryOrder.Core.Domains.Order.Properties.Client), idClient),
Restrictions.Eq(String.Format("{0}.Id", SummaryOrder.Core.Domains.Order.Properties.Provider), idClient))).
SetResultTransformer(new DistinctRootEntityResultTransformer()).
SetFetchMode(SummaryOrder.Core.Domains.Order.Properties.Items, FetchMode.Join);
return criteria.List<SummaryOrder.Core.Domains.Order>() as List<SummaryOrder.Core.Domains.Order>
But I've got duplicates.. When I execute One restriction (without OR) I got distinct collection of orders, but Restriction OR brakes my query. I wanna get distinct(at client yet) collection of orders. What's wrong. Please HELP!
© Stack Overflow or respective owner