I'm trying to create a standard parent-child relationship, code:
Code:
public class ChangeRequest : DomainEntity
{
//...snip
private IList<FurtherComment> m_FurtherComments = new List<FurtherComment>();
public IList<FurtherComment> FurtherComments
{
get
{
return m_FurtherComments;
}
}
public void AddFurtherComment(DateTime postedAt, string postedBy, string content)
{
m_FurtherComments.Add(new FurtherComment(postedAt, postedBy, content));
}
}
public class FurtherComment : DomainEntity
{
//...snip
}
mapping in ChangeRequestItem.hbm.xml:
<bag generic="true" name="FurtherComments" cascade="all-delete-orphan" access="field.pascalcase-m-underscore">
<key column="ChangeRequestItemId" />
<one-to-many class="FB.CRS.Core.FurtherComment, FB.CRS.Core" />
</bag>
As can be seen the relationship is uni-directional from the ChangeRequestItem object, however I run into an issue when adding the FurtherComment object to the ChangeRequestItem whereby the foreign key value is not being inserted into the FurtherComment's table, so I get the following exception:
Cannot insert the value NULL into column 'ChangeRequestItemId', table 'CRS.dbo.CRSFurtherComment'; column does not allow nulls. INSERT fails.
The statement has been terminated.
After some digging I found the following on stackoverflow
http://stackoverflow.com/questions/5558 ... ny-problem which appears to be the same issue, in the answers section he solves it by making the relationship bi-directional, is this really the only way? I don't really want to have the bi-directional relationhip as it makes no sense in the domain model.
Any help is appreciated.
Thanks,
Mike