I have a very simple unidirectional mappings. see below:
public ContactMap()
{
Id(x => x.Id).GeneratedBy.Assigned();
Map(x => x
Try setting inverse
to true
on the mapping and assigning the relationship in code.
Inverse
means that the child is responsible for holding the ID of the parent.
e.g.
var contact = new Contact();
var phoneNumber = new PhoneNumber();
phoneNumber.Contact = contact;
That way, when you do the insert for the PhoneNumber record, NH can insert the ContactId without having to do a separate update.
That's what I used to do in NH 2, I would assume the behaviour still works the same in 3.