title: Soft delete nested entities in EF Core
body: <p>I have some nested entities, and I want to Auto soft-delete children of a record when I soft-delete that record(like hard-delete). How can I do this? And what is the best approach?</p>
  <pre><code>class Base
  {
      bool isDeleted { set; get; }
  }
  
  class A : Base
  {
      //Collection of B
  }
  
  class B : Base
  {
      //Collection of C
  }
  
  class C : Base
  {
      //Collection of D
  }
  ....
  </code></pre>
  <p>For example:</p>
  <p>Table A:</p>
  <pre><code>    Id    ForeignKey(B Id)    isDeleted 
      -------------------------------------
      1        1                 false
  </code></pre>
  <p>Table B:</p>
  <pre><code>   Id    ForeignKey(C Id)    isDeleted
     -------------------------------------
      1        1                 false
      1        2                 false
      1        3                 false
  </code></pre>
  <p>Table C:</p>
  <pre><code>    Id    ForeignKey(D Id)    isDeleted
      -------------------------------------
      1        1                 false
      1        2                 false
      2        3                 false
      2        4                 false
      3        5                 false
      3        6                 false
  </code></pre>
  <p>Code:</p>
  <pre><code>public void SoftDeleteA()
  {
       //A.isDeleted = true;
       //???How to soft-delete related records in B,C,D ,...
       //SaveChanges();
  }
  </code></pre>
  <p>Now when I soft-delete rows from A, all the rows of B and C must also be soft-deleted</p>