开发者

how to remove/delete an 0..1 entity in entity framework 4

开发者 https://www.devze.com 2023-02-02 09:38 出处:网络
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 eve

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;


You would use the object context to delete an entity from the database:

context.DeleteObject(_event.InstallmentPlan);
context.SaveChanges();


You should be able to remove the association by key too:

_event.InstallmentPlanKey = null;

This doesn't remove the object; to do that, you have to then also delete the entity as @Marek explains.

0

精彩评论

暂无评论...
验证码 换一张
取 消