Ok, so I have an object named "Business" (I know, I know, "Business Business Object") When it saved its foreign keys are getting lost somehow. Everything else is saving. I have stepped through the code and followed the object up until the
session.SaveOrUpdate(businessObject);
method. The object at that point is intact and the foreign properties seem to be there. However when it is saved the foreign IDs are not in the Business Table. I can only imagine this may be due to me not mapping them correctly?
Here is where they are being mapped:
<many-to-one insert="false" update="false" name="_Township" column="TownshipId" class="HQData.Objects.Township, HQData" />
<many-to-one insert="false" update="false" name="_User" column="UserId" class="HQData.Objects.User, HQData" />
<many-to-one insert="false" update="false" name ="_SubCategory" column="SubCategoryId" class="HQData.Objects.SubCategory, HQData"/>
Here is where the object is being loaded and saved:
HQData.Objects.Business business = null;
if (BusinessId != 0)
business = BusinessManager.GetBusiness(BusinessId);
else
business = new HQData.Objects.Business();
business._SubCategory = CategoryManager.GetCategory(Convert.ToInt32(ddlCategory.SelectedValue.Trim()));
business.Name = ControlHelper.Sanitize(txtName.Text.Trim());
business.Address1 = ControlHelper.Sanitize(txtAddress.Text.Trim());
business._Township = TownshipManager.GetTownshipByCityorZip(ControlHelper.Sanitize(txtTownship.Text));
business.PhoneNumber = ControlHelper.Sanitize(txtPhone.Text.Trim());
business.FaxNumber = ControlHelper.Sanitize(txtFax.Text.Trim());
business.Email = ControlHelper.Sanitize(txtEmail.Text.Trim());
business.Website = ControlHelper.Sanitize(txtWebsite.Text.Trim());
business.AboutUs = ControlHelper.Sanitize(txtAboutUs.Text.Trim());
business._User = UserManager.GetCurrentUser();
BusinessManager.SaveBusiness(business);
Thank you for your help.