Fluent nHibernate: one-to-many relationship Issue

好久不见. 提交于 2019-11-29 02:41:51

When you have a persistent collection with inverse="false", then the parent object owns the relationship and any changes to the parent's collection will be reflected in the database.

When you have a persistent collection with inverse="true", then the child object owns the relationship and any changes to the child's reference to the parent will be reflected in the database.

Because you set inverse="true", you will need to change the child object's reference to the parent object in order for NHibernate to pick up on it. If you wish NHibernate to pick up on the changes to the relationship whenever you add children to or remove children from the parent's collection, you must set inverse="false" on the collection.

You have to manually set the Installation Property of an Institution, specifically,

Installation installation = TestHelper.CreateAnonymousInstallation();
Institution institution = TestHelper.CreateAnonymousInstitution();
institution.Installation = installation;
installation.Institutions.Add(institution);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!