I'm using NHiberante so I will give you an example of how I would do it. I hope it helps.
Header Class mapping:
Code:
<hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2">
<class name="Header" table="Header" lazy="true">
<id name="HeaderId" type="System.Int32" column="HeaderId" unsaved-value="0">
<generator class="native" />
</id>
<property name="Name" type="System.String" column="Name" not-null="true" length="50" />
</class>
</hibernate-mapping>
HeaderDetail Class mapping
Code:
<hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2">
<class name="HeaderDetail" table="HeaderDetail" lazy="true">
<composite-id name="HeaderDetailPrimaryKey" class="PK_HeaderDetail" unsaved-value="any" access="property">
<key-property name="ColumnId" type="System.Int32" column="ColumnId" />
<key-many-to-one name="HeaderObj" class="Header">
<column name="HeaderId" />
</key-many-to-one>
</composite-id>
<property name="Desc" type="System.String" column="Desc" not-null="false" >
<property name="Qty" type="System.Int32" column="Qty" not-null="false" />
</class>
</hibernate-mapping>
Because on the HeaderDetail class you have a composed ID in order to work, you need to create also the PK_HeaderDetail class which can look something like this:
Code:
[System.SerializableAttribute()]
public class PK_HeaderDetail
{
private int columnId;
private Header headerObj;
public virtual int ColumnId
{
get
{
return this.columnId;
}
set
{
this.columnId= value;
}
}
public virtual Header HeaderObj {
get
{
return this.headerObj;
}
set
{
this.headerObj= value;
}
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public override bool Equals(object obj)
{
if (((obj == null)
|| (obj == System.DBNull.Value)))
{
return false;
}
PK_HeaderDetail entity = ((PK_HeaderDetail)(obj));
return ((ColumnId== entity.ColumnId)
&& (HeaderObj == entity.HeaderObj));
}
}
And inside your HeaderDetail class you can have only these properties (virtual):
HeaderDetailPrimaryKey
Desc
Qty
If there is something that you don't understand please post another message and I can clear it out. Good luck !!!