Entity Framework Core, deleting items from nested collection

That is because the rows in the database are not marked for deletion.

Only new or changed items are updated. 'Missing' items from a collection are not considered to be deleted.

So what you'll need to do is mark the items for deletion yourself. Something like this:

public void Update(Invoice record)
{
    var missingRows = dB.InvoiceRows.Where(i => i.InvoiceId == record.Id)
                        .Except(record.Rows);
    dB.InvoiceRows.RemoveRange(missingRows);

    dB.Invoices.Update(record);
    dB.SaveChanges();
}

Another solution would be to declare a composite primary key InvoiceRow.Id and InvoiceRow.InvoiceId. Now it is an Identifying Relationship. As such, EF Core will indeed delete the child records when they are removed from the parent.

https://stackoverflow.com/a/17726414/7718171

https://stackoverflow.com/a/762994/7718171

remove-from-collection-does-not-mark-object-as-deleted