Fluent nHibernate: Need help with ManyToMany Self-referencing mapping

独自空忆成欢 提交于 2019-12-02 03:27:47

问题


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!


回答1:


Remove Inverse() call



来源:https://stackoverflow.com/questions/1811316/fluent-nhibernate-need-help-with-manytomany-self-referencing-mapping

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