实体框架 - 许多多对多关系
我正在尝试使用 EF 将产品与交易关联起来。目前,它只允许我将同一交易映射到产品一次。
例如,在交易中,尝试添加两个相同的产品是行不通的。它只会存储一个映射吗?
可以这样做吗?或者我应该创建一个解决方法?
I'm trying to use EF to relate products to transactions. Currently it allows me to only map the same transaction to on product only once.
For example, in a transaction, trying to add two of the same product doesn't work. It will only ever store one mapping?
Is it possible to do this? Or should I just create a workaround?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EF 不允许您向多对多关系添加重复项。连接表应该只包含参与表的主键作为表的主键。
您可以通过将连接表映射为实体并创建一个自动递增的 id 作为连接表的 PK 来解决此问题。
EF does not allow you to add duplicates to the many to many relationships. The join table should only contain the primary keys of the participating tables as the PK of the table.
You can workaround this problem by mapping the join table as an entity and creating an auto incremented id as the PK of the join table.