如何在实体框架 4 中删除/删除 0..1 实体
您好,我有一个 Events 表和一个 InstallmentPlans 表。关系是 0..1 :一个事件可以有 0 或 1 个分期付款计划。如果我想删除某个活动的现有 InstallmentPlan,该如何操作?将其设置为 null 似乎不起作用:
_event.InstallmentPlan = null;
Hi I have an Events table and an InstallmentPlans table. The relationship is 0..1 : an Event can have 0 or 1 Installment plans. If I want to remove the existing InstallmentPlan for an event, how do I do this? Setting it to null doesn't seem to work:
_event.InstallmentPlan = null;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用对象上下文从数据库中删除实体:
You would use the object context to delete an entity from the database:
您也应该能够通过密钥删除关联:
这不会删除该对象;为此,您还必须按照 @Marek 的解释删除该实体。
You should be able to remove the association by key too:
This doesn't remove the object; to do that, you have to then also delete the entity as @Marek explains.