I have in my Database a Contact table and a Phone table, in the phone table there is column "ContactId" with a key that references the phone to the contact.
In the key options in the server I set its delete option to 'Cascade'.
Now when I attempt to delete a contact using the context:
Dim contact As Contact 'The contact I want to delete.
Dim context As New Entities 'The ObjectContext.
context.DeleteObject(contact)
context.SaveChanges()
The above statement throws an UpdateException letting me know that the Contact still have Phone records whose ContactId col is set to its ID.
Now I know that I can do it manually and delete first all the related phones then remove the contact, but I am looking for a more efficient way, I want all this should be done automatically.
Any suggestions and practices are welcomed.
Thanks.