Fluent nhibernate mapping problem: many to many self join with additional data

☆樱花仙子☆ 提交于 2019-12-04 12:29:05

I Finally found a solution after much research. So though I would post it in case it can help anyone else in the future. As PostRelation had additional data, it needed to be an entity in its own right.

---PostRelationMap

        Id(x => x.Id, "PostRelationId").GeneratedBy.Identity();

        References(x => x.ParentPost, "ParentPostId")
            .ForeignKey("FK_PostRelation_ParentPost")
            .Fetch.Join()
            .LazyLoad();

        References(x => x.ChildPost, "ChildPostId")
            .ForeignKey("FK_PostRelation_ChildPost")
            .Fetch.Join()
            .LazyLoad();

        Map(x => x.RelationshipType).CustomType<int>().Not.Nullable();

---PostMap

    HasMany(x => x.ChildPosts)
            .Access.CamelCaseField(Prefix.Underscore)
            .Cascade.AllDeleteOrphan()
            .KeyColumn("ChildPostId")
            .LazyLoad();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!