I have created an extensibility method for deleting one of my Linq To Sql objects called Reservation.
Well, in this partial method I created, I want to update some other objects. I can't seem to get the update to be persisted in the database. Here is my partial method for deleting the reservation.
public partial class LawEnforcementDataContext
{
partial void DeleteReservation(Reservation instance)
{
// Get ID's of those seated in course
var roster = new Roster(this, instance.CourseID);
var seated = from r in roster.All
where r.WaitingList == false
select r.ID;
// delete the reservation
this.ExecuteDynamicDelete(instance);
// get seated id's not in original seated ids
var newlySeated = from r in roster.All
where r.WaitingList == false && !seated.Contains(r.ID)
select r.ID;
var reservations = this.Reservations.Where(r => newlySeated.Contains(r.ID));
foreach (var r in reservations)
{
r.Confirmed = false;
// Have tried doing nothing, thinking calling code's db.SubmitChanges() would do the trick
//this.ExecuteDynamicUpdate(r); HAVE TRIED THIS
}
//this.SubmitChanges(); HAVE TRIED THIS
}
}
The delete is taking place but the update is not. Commented in the last few lines are some of the things I have tried.
Any ideas? Thanks!
EDIT
Here is what I have done to solve this:
public override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)
{
ChangeSet delta = GetChangeSet();
foreach (var res in delta.Deletes.OfType<Reservation>())
{
// Get ID's of those seated in course
var roster = new Roster(this, res.CourseID);
var seated = from r in roster.All
where r.WaitingList == false
select r.ID;
base.SubmitChanges(failureMode);
// get seated id's not in original seated ids
var newlySeated = from r in roster.All
where r.WaitingList == false && !seated.Contains(r.ID)
select r.ID;
var reservations = this.Reservations.Where(r => newlySeated.Contains(r.ID));
foreach (var r in reservations)
{
r.Confirmed = false;
}
}
base.SubmitChanges(failureMode);
}