流畅的 nhibernate m-to-m 与列
我习惯了 hbm 文件,最近开始使用 Fluent nhibernate。
在两个实体 A 和 B 之间创建 m-to-m 关系非常简单
在实体 A 中,我创建:
public virtual IList<B> Bs { get; set; }
然后使用:
mapping.HasManyToMany(x => x.Bs);
就是这样,我可以这样做:
A a = new A();
a.Bs.Add(b);
我的问题是我想在我的实体中添加一个附加列保存两个外键的专用多对多数据库表。在 FNH 中实现这一目标的最简单方法是什么?
我是否必须为点对点关系创建一个专用实体,或者是否有更简单的解决方案?
I am used to hbm files and have started using fluent nhibernate recently.
Creating an m-to-m relationship between two entities A and B is quite simple
In entity A, I create:
public virtual IList<B> Bs { get; set; }
and then I use:
mapping.HasManyToMany(x => x.Bs);
That’s it and I can do:
A a = new A();
a.Bs.Add(b);
My problem is that I would like to have an additional column in my dedicated m-to-m database table which holds the two foreign keys. What is the simplest way to achieve this in FNH?
Would I have to create a dedicated entity for the m-to-m realtionship or is there a simpler solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须将具有附加数据关系的多对多映射为两个一对多关系。因此,是的,您确实需要在模型中为此创建一个专用实体。
You have to map many-to-many with additional data relationships as two one-to-many relationships. So, yes, you do need to create a dedicated entity in your model for this.