开发者

nhibernate : mapping to column other than primary key

I have the following map. My intention is for the order.BasketId to map to orderItem.BasketId. Tho when i look at the sql i see that it's mapping 开发者_Python百科order.Id to orderItem.BasketId. How do i define in my order map which order property to map against basketId. It seems to default to the primary key.

 <class name="Order" table="Orders">
    <id name="Id" type="Int32" column="Order_ID" unsaved-value="0">
      <generator class="identity"/>
    </id>

    <property name="BasketId" column="Basket_ID" type="Int32"/>
    <set name="OrderItems" table="item_basket_contents" generic="true" inverse="true"  >
      <key column="Basket_ID" />
     <one-to-many class="EStore.Domain.Model.OrderItem, EStore.Domain"/>      
    </set>
  </class>

and orderItem

  <class name="OrderItem" table="Item_Basket_Contents">
    <id name="Id" type="Int32" column="ID" unsaved-value="0">
      <generator class="identity"/>
    </id>

    <property name="BasketId" column="Basket_ID" type="Int32"/>
  </class>


Use the following:

<key column="Basket_ID" property-ref="BasketId" />

That's it.


Can you change the structure? I would have a Basket entity, which contains the order items. Your order then refers to this basket, and the basket contains the items. The explicit basketID in Order is circumventing some of the ORM that hibernate does.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜