Fluent nHibernate: one-to-many relationship Issue

后端 未结 2 1449
鱼传尺愫
鱼传尺愫 2020-12-16 07:47

I have a problem with one-to-many relationships. I have the following domain classes:

public class Installation : Entity
{        
    pu         


        
相关标签:
2条回答
  • 2020-12-16 08:18

    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.

    0 讨论(0)
  • 2020-12-16 08:29

    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);
    
    0 讨论(0)
提交回复
热议问题