EF:从多对多(桥接)表中删除
我有一个与此类似的设置:
Table1
id1 (int)
name (varchar)
Table 2
id2 (int)
name (varchar)
Bridge
id1 (fk to Table1)
id2 (fk to Table2)
众所周知,在 EF 中,不存在代表 Bridge 的对象。相反,Table1 将包含 Table2 的集合,而 Table2 将包含 Table1 的集合。
假设我有一条 Table1 记录与 5 个 Table2 相关联。
如何高效删除所有 Table2 引用?我只想将它们从 Bridge 表中删除......
I've got a setup similar to this:
Table1
id1 (int)
name (varchar)
Table 2
id2 (int)
name (varchar)
Bridge
id1 (fk to Table1)
id2 (fk to Table2)
As you all know, in the EF, an object won't exist to represent Bridge. Instead, Table1 will contain a collection of Table2's and Table2 will contain a collection of Table1's.
Let's say I have a single Table1 record associated with 5 Table2's.
How do I delete all Table2 references efficiently? I only want them deleted from the Bridge table...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您只需清除引用,然后保存更改 - 我认为它不会删除 Table2 记录,但我可能是错的:
I think you just clear the references and then save the changes - I don't think it deletes the Table2 records, but I may be wrong: