I'm having a hard time deleting an object tree. My model doesn't use any kind of built-in cascade deletion mechanism, so I have to perform the explicit deletion of each of the related entities.
The entity I want to delete has 3 levels of indirection (navigation properties)
class Parent
{
public ICollection<Child> Children { get; set; }
}
class Child
{
public ICollection<Grandchild> Grandchildren { get; set; }
}
public class Grandchild
{
}
my DbContext is
public class Context
{
DbSet<Parent> Root {get; set;}
DbSet<Grandchild> Grandchildren {get; set;}
}
Please, notice that the context doesn't expose a DbSet for the class Children
.
So, what's the correct way to delete everything under a Parent
?