两个实体中的多对多集合 Fluent NHibernate
我正在尝试在 Fluent NHibernate 中映射多对多关系,但遇到了一个问题,很可能只是我刚接触该工具。
我有 2 个实体:用户和项目。一个用户可以在多个项目中,一个项目可以有多个用户。
在我的用户地图中,
HasManyToMany(x => x.Projects).Inverse();
当我将相同的地图放入项目中时,我得到一个异常,因为表名称相反。另外,我认为根据这篇文章我不需要它: Fluent NHibernate Many-to-Many
我正在逐步执行此操作以查看它是否有效:
var user = _userRepository.FindByUserName("Josh");
var projects = user.Projects;
var user2 = projects[0].Users;
发生的情况是项目返回包含我的项目的集合。但 User2 为空。我希望 user2 是一个包含与 user 相同的用户的集合。
那么我做错了什么。谢谢。
I'm trying to map a manyToMany relationship in Fluent NHibernate and running into a problem that's most likely just me being new at the tool.
I have 2 Entities, User and Project. A User can be on many projects and a project can have many users.
In my map for User I have
HasManyToMany(x => x.Projects).Inverse();
When i put the identical map in project i get an exception because the table name is opposite. Also i thought I didnt need it based on this post: Fluent NHibernate Many-to-Many
I'm stepping through this to see if it is working:
var user = _userRepository.FindByUserName("Josh");
var projects = user.Projects;
var user2 = projects[0].Users;
What happens is projects returns a collection containing my project. User2 is null though. I would expect user2 to be a collection containing the same user as user.
So what am i doing wrong. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试仅将 .Inverse() 放在一个映射上。
UserMap:
ProjectMap:
如果这不起作用,请尝试指定表名称。
用户地图:
项目地图:
Try putting .Inverse() on one mapping only.
UserMap:
ProjectMap:
If that doens't work try specifing the table name.
UserMap:
ProjectMap: