Well, I have one-to-many related model:
public class Parent
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<
Cascading delete has no effect here because you don't delete the parent
but just call InsertOrUpdate
. The correct procedure is to delete the children one-by-one, like so for example:
using (var context = new MyContext())
{
var parent = context.Parents.Include(p => p.Children)
.SingleOrDefault(p => p.Id == parentId);
foreach (var child in parent.Children.ToList())
context.Children.Remove(child);
context.SaveChanges();
}