流利的nHibernate:需要ManyToMany自引用映射的帮助 [英] Fluent nHibernate: Need help with ManyToMany Self-referencing mapping

查看:114
本文介绍了流利的nHibernate:需要ManyToMany自引用映射的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的用户实体中,我已经创建了一个名为User的实体,可以有一个名为Friends的其他用户的列表公共虚拟IList朋友{get;私人设置;}属性,并在构造函数中创建列表。我也有一个AddFriends方法,将用户添加到好友列表中。

在我的UserMapping类中,我有下面的代码来映​​射关系:



$ p $ HasManyToMany(x => x.Friends)
.ParentKeyColumn(UserId)
.ChildKeyColumn(FriendId)
.Table(UserFriends)
.Inverse()。Cascade.SaveUpdate()。Not.LazyLoad();

所有的表格都被正确创建,但是UserFriends表格和每个返回的用户有空的朋友列表。



有什么建议吗?

谢谢!

解决方案

移除反向()调用


I have an entity called User which can have a list of other Users called Friends (kinda like Facebook).

In my User entity, I've delcared a public virtual IList Friends { get; private set;} property, and an creating the list in the constructor. I also have an "AddFriends" method that adds Users to the Friends list.

In my UserMapping class I have the following code to map the relationship

HasManyToMany(x => x.Friends) 
                .ParentKeyColumn("UserId")
                .ChildKeyColumn("FriendId")
                .Table("UserFriends")
                .Inverse().Cascade.SaveUpdate().Not.LazyLoad();

All the tables get created correctly but nothing ever gets put in the UserFriends table and every user that comes back has an empty Friends list.

Any advice?

Thanks!

解决方案

Remove Inverse() call

这篇关于流利的nHibernate:需要ManyToMany自引用映射的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆