我有一个对象OtherFaclilityEntity,它包含一个ILF的OtherFcs对象,映射如下:
public OtherFacilityMap()
{
Schema("SOME");
Table("OTHER_FACILITY");
Id(x => x.Id, "OTHER_FACILITY_S").GeneratedBy.TriggerIdentity();
Map(x => x.RowCreator, "ROW_CREATOR");
Map(x => x.RowCreateDate, "ROW_CREATE_DATE");
Map(x => x.Description, "DESCRIPTION");
Map(x => x.ExistenceKdNm, "R_EXISTENCE_KD_NM");
References(x => x.FacilityClassItem, "FACILITY_CLASS_S").LazyLoad(Laziness.False).Fetch.Join().Not.Insert().Not.Update();
HasMany(x => x.FacilityCmList).KeyColumn("WHOLE_S").Fetch.Subselect().Not.LazyLoad();
}
当我尝试在OtherFacility实体上执行SaveOrUpdate时,它还会更新FacilityCmList中的所有实体,这很好,但是在最后运行的sql中尝试删除父对象和子对象之间的所有关系:
NHibernate.SQL: 2011-07-19 10:29:33,111 [361] DEBUG NHibernate.SQL [(null)] - UPDATE SOME.FACILITY_CMS SET WHOLE_S = null WHERE WHOLE_S = :p0;:p0 = '26021842'
我认为它与我的绘图有关,有什么想法吗?
答案 0 :(得分:0)
阅读NHibernate sets Foreign Key in secondary update rather than on initial insert violating Not-Null Constrain on key column后,我发现我需要将Inverse添加到HasMany关系中。
HasMany(x => x.FacilityCmList).KeyColumn("WHOLE_S").Fetch.Subselect().Inverse().Not.LazyLoad();