“多到一个”的在组件问题NHibernate

使用以下映射,BillingAddress.Country被正确映射,但ShippingAddress.Country始终为null。也许是因为同等属性的名字?但他们是不同的对象......任何想法如何解决它? 谢谢你。
<?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>
    
已邀请:
您应该从映射和送货地址的映射中删除CountryID,因为它已经在与Country的多对一关系中定义。除此之外,映射看起来还不错。如果组件中的所有值都为null,则组件将为null。因此,如果所有送货地址字段均为空,则ShippingAddress组件将为null。     

要回复问题请先登录注册