how to remove/delete an 0..1 entity in entity framework 4
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.
精彩评论