好的,所以我有一个名为“Business”的对象(我知道,我知道,“Business Business Object”)当它保存它的外键时不知何故丢失了。其他一切都在节省。我已经逐步完成了代码并跟踪了对象,直到
session.SaveOrUpdate(businessObject);
方法。那时的物体是完整的,外来的属性似乎在那里。但是,当它被保存时,外国 ID 不在业务表中。我只能想象这可能是因为我没有正确映射它们?
这是它们被映射的位置:
<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"/>
这是加载和保存对象的位置:
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);
感谢您的帮助。