I have a table Donations which has a CampaignID column that relates to the Campaigns Table. I need to insert a 0 in the CampaignID column instead of Null if the Campaign is
Try loading the Campaign object whose DB identity is 0 from the DB. It will then be a fully persistent object. You should then be able to set it and persist the donation.
If this works, you need to change the ID property mapping of the Campaign object. Nh is unable to determine that your transient campaign object created here :
new Campaign() {CampaignID = 0};
is actually a detached object. What you should do is add an 'unsaved value' into your mapping of say, -1. Now Nh can tell the difference between your valid detached campaign with a DB identity Id of 0, and transient new campaigns with Ids of -1. Then remember to set the Id for newly created campaigns to -1.