«многие-к-одному» в рамках проблемы с компонентами NHibernate - PullRequest
0 голосов
/ 19 июля 2010

При следующем сопоставлении BillingAddress.Country отображается правильно, но ShippingAddress.Country всегда равно нулю Может это из-за равных свойств имени? но это разные объекты ... Есть идеи как это исправить? Спасибо вперед.

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="KapsNet.QuickOffice.Models" namespace="KapsNet.QuickOffice.Dto">
 <class name="Order" table="`Order`" >
  <id name="ID" type="System.Int32" column="ID">
   <generator class="identity"/>
  </id>
  <property name="CreateDate" column="CreateDate" type="System.DateTime" not-null="true" />
  <property name="ClientContactID" column="ClientContactID" type="System.Int32" not-null="true" />
  <component name="BillingAddress" class="AddressInfo">
   <property name="Address" column="BillingAddress" type="System.String" not-null="false" length="255"/>
   <property name="ZipCode" column="BillingZipCode" type="System.String" not-null="false" length="50"/>
   <property name="City" column="BillingCity" type="System.String" not-null="false" length="50"/>
   <property name="CountryID" column="BillingCountryID" type="System.Int32" not-null="true" />
   <property name="Phone" column="BillingPhone" type="System.String" not-null="false" length="50"/>
   <many-to-one name="Country" column="BillingCountryID" class="Country"  update="0"  insert="0" />
  </component>
  <component name="ShippingAddress" class="AddressInfo">
   <property name="Address" column="ShippingAddress" type="System.String" not-null="false" length="255"/>
   <property name="ZipCode" column="ShippingZipCode" type="System.String" not-null="false" length="50"/>
   <property name="City" column="ShippingCity" type="System.String" not-null="false" length="50"/>
   <property name="CountryID" column="ShippingCountryID" type="System.Int32" not-null="true" />
   <property name="Phone" column="ShippingPhone" type="System.String" not-null="false" length="50"/>
   <many-to-one name="Country" column="ShippingCountryID" class="Country"  update="0"  insert="0" />
  </component>
  <many-to-one name="ClientContact" column="ClientContactID" class="ClientContact"  update="0"  insert="0" />
  <bag name="OrderItemList" table="OrderItem" inverse="true" lazy="true" cascade="delete">
   <key column="OrderID" />
   <one-to-many class="OrderItem"/>
  </bag>
 </class>
</hibernate-mapping>

1 Ответ

1 голос
/ 19 июля 2010

Вы должны удалить CountryID из сопоставлений для адреса выставления счета и доставки, поскольку он уже определен в отношении «многие к одному» со страной. В остальном сопоставления выглядят хорошо. Компоненты будут нулевыми, если все значения в компоненте равны нулю. Таким образом, если все поля адреса доставки имеют значение NULL, компонент ShippingAddress будет иметь значение NULL.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...