unable to delete dinner

Nov 3, 2009 at 12:14 AM

I'm a fairly new .net developer attempting to learn MVC by building the sample application - it's been slow going due to a number of mostly self-inflicted issues, but it's been a great learning experience, so a big thanks for a practical and worthwhile introduction to MVC.

So, the problem is that I'm stuck trying to delete a dinner - I get a "Rule violations prevent saving" error in DinnerRepository.Save(), which is just: db.SubmitChanges() as you can see in the stack trace, but nothing after that is meaningful to me:

System.Data.Linq.ChangeProcessor.SendOnValidate(MetaType type, TrackedObject item, ChangeAction changeAction) +197
System.Data.Linq.ChangeProcessor.ValidateAll(IEnumerable`1 list) +182
System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode) +76
System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode) +331
System.Data.Linq.DataContext.SubmitChanges() +19
NerdDinner.Models.DinnerRepository.Save() in D:\Visual Studio 2008\Projects\NerdDinner\NerdDinner\Models\DinnerRepository.cs:70

If I delete the RSVPs (but not the dinner) by commenting out the line in DinnerRepository.Delete() as shown below, the subsequent Save() works fine and deletes all the RSVPs for that dinner:

public void Delete(Dinner dinner)
{    db.RSVPs.DeleteAllOnSubmit(dinner.RSVPs);
      //db.Dinners.DeleteOnSubmit(dinner);
}

I can Create and Edit dinners without any problem, but I don't know if that's relevant - seems like these are not RuleViolations, but some type of database misconfiguration. So, I double-checked the tables - RSVP.RsvpID and Dinners.DinnerID are the primary keys, and there's a relationship between Dinners.DinnerID (primary) and  RSVP.DinnerID (foreign). I had missed the step of adding the primary key to the RSVP, so I did that and ran the "Run Custom Tool" utility to regenerate the NerdDinnerDataContext class, then rebuilt the project and still get the same error.

So I'm not sure what else to check - any help would be greatly appreciated...

Nov 3, 2009 at 12:39 AM

Can't delete this discussion, so I'll just update it - I commented out all the RuleViolation tests in GetRuleViolations(), and was able to delete the dinner, so it was a Rule Violation after all.  The exception that gets thrown was in GetRuleViolations(), so I guess I just wasn't very observant - I just need to figure out which rule was being violated...