I’m using MVC3 to build a web application. In this application I have an entity which has x number of virtual collections which themselves could hold y number of virtual collections.
Is there a way in which I can “simulate” a cascade delete such that when I delete the top entity, it first tries to delete the child collection entities recursively.
I know I could do it with the database cascading options (and a couple of triggers) but I would really like to know if this is possible in C#.
EDIT:
Top entity:
public class Tournament {
public int TournamentID { get; set; }
// other properties
public virtual ICollection<Official> Officials { get; set; }
}
Child:
public class Official {
public int OfficialID { get; set; }
// other properties
public virtual ICollection<Matches> Matches { get; set; }
}
So when I delete a Tournament entity, it should also delete the Officials and in the Officials it should delete the Matches
Just make sure the association from child to parent does not allow nulls.
Then Delete the parent.