title: Entity Framework Core one to zero or one on delete
body: <p>I implemented a junction table based on <a href="https://entityframeworkcore.com/knowledge-base/54497784/entity-framework-core-zero-or-one-to-zero-or-one-relation" rel="nofollow noreferrer">this link</a>.</p>
  <pre><code>public class Car
  {
      public int ID { get; set; }
      public string Brand { get; set; }
      public string Type { get; set; }
      public CarDriver CarDriver { get; set; }
  }
  
  public class Driver
  {
      public Driver()
      { }
      public int ID { get; set; }
      public string Name { get; set; }
      public CarDriver CarDriver { get; set; }
  }
  
  public class CarDriver
  {
      public int CarID { get; set; }
      public Car Car { get; set; }
      public int DriverID { get; set; }
      public virtual Driver Driver { get; set; }
  }
  
  protected override void OnModelCreating(ModelBuilder modelBuilder)
  {
      var carDriverEtb = modelBuilder.Entity&lt;CarDriver&gt;();
      carDriverEtb.HasKey(cd =&gt; new { cd.CarID, cd.DriverID });
      carDriverEtb.HasIndex(cd =&gt; cd.CarID).IsUnique();
      carDriverEtb.HasIndex(cd =&gt; cd.DriverID).IsUnique();
  }
  </code></pre>
  <p>I would like to delete automatically(cascade) both CarDriver and Driver when Car will be deleted. But only CarDriver record will be deleted.</p>
  <p>Any advice or assistance would be greatly appreciated.</p>