Nhibernate - 在类映射</bag> </join>中组合<join>和<bag>标记

时间:2013-06-24 12:39:20

标签: c# nhibernate nhibernate-mapping

我需要你的帮助。

我使用<Join>代码制作了我的课程,并希望同时添加<bag>

类似的东西:

  <class name="Hilan.HilanNet.Common.Pension.ClassA,Hilan.HilanNet.Common" table="ClassA_VW">
    <cache usage="read-write"/>
    <composite-id>
      <key-property name="columnA" column="sqlColumnA"/>
      <key-many-to-one name="columnB" column="sqlColumnB" class="Hilan.HilanNet.Common.Pension.ClassB, Hilan.HilanNet.Common" />
    </composite-id>
    other properties
    <join optional="true" table="AdditionalColumns_TB" inverse="false" >
      <key>
        <column name="columnA" />
        <column name="columnB"/>
      </key>
      <property name="propertyA" />
    </join>
      here I want to add the bag
    <bag
           name="Details"
           lazy="true"
           inverse="true"
           access="nosetter.camelcase-underscore"
           table="Details_VW" cascade="all">
      <cache usage="read-only"/>
      <key>
        <column name="ColumnA" />
        <column name="ColumnB"/>
      </key>
      <property name="PrincipalId" />
    </bag>
  </class>   

但是我收到了错误 -

“命名空间'urn:nhibernate-mapping-2.2'中的元素'class'在命名空间中有无效的子元素'bag'”

为什么我不能这样做?

谢谢!

1 个答案:

答案 0 :(得分:2)

元素<join>必须是<class>中无法识别后的每个元素中的最后一个元素。

<class name="Hilan.HilanNet.Common.Pension.ClassA,Hilan.HilanNet.Common" table="ClassA_VW">
<cache usage="read-write"/>
<composite-id>
  <key-property name="columnA" column="sqlColumnA"/>
  <key-many-to-one name="columnB" column="sqlColumnB" class="Hilan.HilanNet.Common.Pension.ClassB, Hilan.HilanNet.Common" />
</composite-id>
<bag
       name="Details"
       lazy="true"
       inverse="true"
       access="nosetter.camelcase-underscore"
       table="Details_VW" cascade="all">
  <cache usage="read-only"/>
  <key>
    <column name="ColumnA" />
    <column name="ColumnB"/>
  </key>
  <property name="PrincipalId" />
</bag>
<join optional="true" table="AdditionalColumns_TB" inverse="false" >
  <key>
    <column name="columnA" />
    <column name="columnB"/>
  </key>
  <property name="propertyA" />
</join>
</class>