View Single Post
  #5 (permalink)  
Old October 12th, 2010, 04:54 PM
Ole F Ole F is offline
Authorized User
 
Join Date: Sep 2010
Posts: 13
Thanks: 1
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by kermit1965 View Post
Try:
public void Add(Dinner dinner)
{
entities.AddToDinner(dinner);
}
public void Delete(Dinner dinner)
{
foreach (var rsvp in dinner.RSVP)
{
entities.DeleteObject(dinner.RSVP);
entities.DeleteObject(dinner);
}
kermit1965, I guess you will get a problem with your code - especially if there are two (or more) RSVP's to a dinner!

Why? Because in you "foreach" loop you first delete the first rsvp. Then you (within your loop) delete the dinner. I guess your application will crash when going to the next RSVP (or maybe the other RSVP's will just stay in the database undeleted...)