NHibernate的。不同的父母抚养孩子

时间:2010-06-01 03:38:07

标签: nhibernate criteria

我有共同的NH映射;

  <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>

希望按此标准获取列表

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>

但我有重复..当我执行一个限制(没有OR)时,我得到了明确的订单集合,但限制或制动我的查询。我想要明确(在客户端)订单的集合。怎么了。请帮忙!

这个hql正在运行。为什么我不能通过条件API获得此结果?

       select distinct o from Order o left join fetch o.Items where o.Client.Id=1 or o.Provider.Id=1

1 个答案:

答案 0 :(得分:0)

检查您的提供商的映射:

<many-to-one name="Provider" class="SummaryOrderClient, SummaryOrder.Core"     column="summary_order_provider_id"
           cascade="none"/>

班级名称错了!?