好的,所以我有一个名为“商业”的对象(我知道,我知道,“商业商业对象”) 当它保存时,它的外键会以某种方式丢失。其他一切都在节省。我已经完成了代码并跟踪了对象直到
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);
感谢您的帮助。
答案 0 :(得分:1)
将插入更新属性设置为true或将其删除。
答案 1 :(得分:0)
你的意思是business._SubCategory.SubCategoryId
并且不确定GetCurrentUser会返回什么,但是如果Id也是......
business._User.UserId?