C# – NHibernate nested class mapping issue

cmappingnhibernate

I have below classes. How can I write mapping document for MainBranch.Id column. I have no branch table in database, just want to use branchId for MAINBRANCHCODE. Any Idea?

public class Bundle
        {
            public virtual Decimal Id { get; set; }       
            public virtual BundleEntranceInformation Information { get; set; } 
        }
    public class BundleEntranceInformation
        {
            public virtual Branch MainBranch { get; set; }      
        }
    public class Branch
        {
            public virtual short Id { get; set; }       
        }

My mapping document:

<class name="PromissoryNotes.Server.Data.Bundle, PromissoryNotes.Server.Data" table="BUNDLE" lazy="true">
    <id name="Id" column="ID" type="Decimal">
      <generator class="increment" />
    </id>   
    <property name="Information.MainBranch.Id" column="MAINBRANCHCODE" type="short"></property>

  </class>

Best Answer

Use a component mapping

<class name="BundleEntranceInformation">
  <component name="MainBranch">
    <property name="Id" column="MAINBRANCHCODE"/>
  </component>
</class>
Related Topic