流利的nhibernate映射问题:多对多的自我加入额外的数据 [英] Fluent nhibernate mapping problem: many to many self join with additional data
问题描述
| Post | | PostRelation |
| ------------------ | | ----------------- |
| PostId | 1 -------- * | ParentPostId |
| ---其他东西--- | 1 -------- * | ChildPostId |
| | | RelationType |
理想情况下,Id就像一个名为relatedPosts的邮件属性一样
Dictionary< RelationType,IList< Post>>
但是在最后一刻,我只是用一个
IList< PostRelation> ;.
我成功地使用了多对多来获取相关的帖子,但是这种方法丢失了附加数据。 / p>
任何建议??
研究。所以虽然我会张贴它,以防万一以后可以帮助其他人。
由于PostRelation有额外的数据,它必须是一个实体。
--- PostRelationMap
Id(x => x.Id,PostRelationId)。GeneratedBy.Identity();
引用(x => x.ParentPost,ParentPostId)
.ForeignKey(FK_PostRelation_ParentPost)
.Fetch.Join()
.LazyLoad );
引用(x => x.ChildPost,ChildPostId)
.ForeignKey(FK_PostRelation_ChildPost)
.Fetch.Join()
.LazyLoad );
$ b $ Map(x => x.RelationshipType).CustomType< int>()。Not.Nullable();
--- PostMap
HasMany(x => x.ChildPosts)
.Access.CamelCaseField(Prefix.Underscore)
.Cascade.AllDeleteOrphan()
.KeyColumn(ChildPostId)
.LazyLoad();
I am struggling with mappings for the following sql tables
|Post | |PostRelation |
|------------------| |-----------------|
|PostId |1--------*|ParentPostId |
|---other stuff--- |1--------*|ChildPostId |
| | |RelationType |
Ideally Id like a property on post called relatedPosts as
Dictionary <RelationType,IList<Post>>
But at the minute Id just settle for a property on post with an
IList<PostRelation>.
I successfully used a many to many to get related posts, but this method loses the addtional data.
Any suggestions??
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();
这篇关于流利的nhibernate映射问题:多对多的自我加入额外的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!