Free nhibernate mapping problem: many of many join additional data

I am struggling with mappings for the following sql tables

   |Post              |          |PostRelation     |
   |------------------|          |-----------------|
   |PostId            |1--------*|ParentPostId     |
   |---other stuff--- |1--------*|ChildPostId      |
   |                  |          |RelationType     |

Ideal Id, as a property in post called relatedPosts as

 Dictionary <RelationType,IList<Post>>

But for a minute Id just agrees to the property in the mail with

  IList<PostRelation>.

I have successfully used many for many to receive related messages, but this method loses additional data.

Any suggestions

+3
source share
1 answer

, . , , - . PostRelation , .

--- 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();
+4

Source: https://habr.com/ru/post/1732326/


All Articles