View Single Post
  #8 (permalink)  
Old November 16th, 2010, 03:56 PM
johnhu johnhu is offline
Registered User
 
Join Date: Nov 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Ole F View Post
I figured out how to make it work:

Code:
public void Delete(Dinner dinner)
{
    foreach(var rsvp in dinner.RSVPs)
    {
        entities.DeleteObject(rsvp);
    }
    entities.DeleteObject(dinner);
}
This doesn't seem to work. At least not for me. I got it to work by making a copy of the RSVP collection and iterating through the copy. Try this:

Code:
public void Delete(Dinner dinner) {
    List<RSVP> tempRsvps = dinner.RSVPs.ToList<RSVP>();
    foreach (var rsvp in tempRsvps) {
        entities.DeleteObject(rsvp);
    }
    entities.DeleteObject(dinner);
}