Fluent NHibernate one-to-many relationship setting foreign key to null

自古美人都是妖i 提交于 2019-12-03 15:52:35

Set Applicant.Tags to Inverse will instruct NHibernate to save Tags after the Applicant.

public class ApplicantMap : ClassMap<Applicant>
{
    public ApplicantMap()
    {
        Id(x => x.Id);

        HasMany(x => x.Tags).Cascade.All().Inverse();
    }
}

More detail:

Inverse (as opposed to .Not.Inverse()) means the other side of the relationship (in this case, each Tag) is responsible for maintaining the relationship. Therefore, NHibernate knows that the Applicant must be saved first so that Tag has a valid foreign key for its Applicant.

Rule of thumb: The entity containing the foreign key is usually the owner, so the other table should have Inverse

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