Cascade Delete - EF Core | Microsoft Docs[
^]
Assuming this is a
one-to-one relationship[
^]:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Client>()
.HasOne(c => c.info)
.WithOne(i => i.client)
.HasForeignKey<Client>(c => c.infoId)
.OnDelete(DeleteBehavior.Cascade);
}
You'll need to add the reverse navigation property from
Info
to
Client
as well.
public class Info
{
public Client client { get; set; }
}