How to remove child one to many related records in EF code first database?

后端 未结 5 1970
逝去的感伤
逝去的感伤 2020-12-01 00:57

Well, I have one-to-many related model:

public class Parent
{
    public int Id { get; set; }
    public string Name { get; set; }
    public ICollection<         


        
5条回答
  •  攒了一身酷
    2020-12-01 01:09

    This is called "deleting orphans".

    Can EF automatically delete data that is orphaned, where the parent is not deleted?

    I don't know how it works in EF6 but in EF Core it works fine https://docs.microsoft.com/en-us/ef/core/saving/cascade-delete so you don't necessarily need to delete the parent for cascades to work.

    Delete orphans examples

提交回复
热议问题