Fluent Nhibernate 外键映射
我有桌子:
玩家
Id : int - 主键
名称:字符串
BowlerType
Id : int - 主键
描述:字符串
PlayerBowlerType
PlayerId :引用 Player.Id 的 int 不为 null 外键
BowlerTypeId : int not null 引用 BowlerType.Id 的外键
玩家可以确认多种保龄球类型。这是一些示例数据
玩家
1 |彼得
2 |约翰
BowlerType
6 |慢
7 |快速
PlayerBowlerType
1 | 6
1 | 7
2 | 7
I have the tables:
Player
Id : int - primarykey
Name : string
BowlerType
Id : int - primarykey
Description : string
PlayerBowlerType
PlayerId : int not null foreign key referencing Player.Id
BowlerTypeId : int not null foreign key referencing BowlerType.Id
A player can confirm to many bowling types. heres some example data
Player
1 | Peter
2 | John
BowlerType
6 | Slow
7 | Fast
PlayerBowlerType
1 | 6
1 | 7
2 | 7
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里您需要的是一个与您的 PlayerBowlerType 一起使用的复合 id。此设置应该有效:
从技术上讲,您可以在没有身份对象的情况下执行此操作(将删除 PlayerBowlerTypeId 类型,并将代码直接放入 PlayerBowlerType 中并进行适当调整),但我遇到了许多问题(3-4 个单独的错误)这样做造成的。其中之一被讨论这里。
虽然我讨厌更改域对象来弥补 ORM 系统中的错误,但如果您只使用 PlayerBowlerTypeId 类型,它将为您省去很多麻烦。
只要您修改映射以使用实际的表和列名称(以及您需要对特定设置的映射执行的任何其他操作),这就应该有效。
What you need here is a composite id to use with your PlayerBowlerType. This setup should work:
You can technically do this without an identity object (the PlayerBowlerTypeId type would be removed and the code placed directly into the PlayerBowlerType and suitably adapted), but I've had a number of problems (3-4 separate bugs) caused by doing this. One of them is discussed here.
While I hate changing the domain objects to compensate for bugs in the ORM system, if you just use the PlayerBowlerTypeId type, it will save you a lot of headaches.
This should work as long as you modify the mapping to use your actual table and column names (and whatever else you need to do with the mapping for your particular setup).
我认为我们可以使用 HasManytoMany。
根据您的要求,您必须创建一个包含玩家和投球手类型 ID 的表。这是多对多的关系。
如果您查看此网站: https://github.com/jagregory/ fluid-nhibernate/wiki/入门
商店和产品的映射与您想要的映射相同。
I think we can use HasManytoMany.
Based from your requirement, you would have to create a table that contains the ids of the player and bowler type. This has a many to many relationship.
If you would look at this site: https://github.com/jagregory/fluent-nhibernate/wiki/Getting-started
The mapping for Store and Products is the same as your intended mapping.