It is SQL Server error 1785: SQL Server refuses a foreign key with ON DELETE CASCADE when the table can already be reached by another cascade path, or the cascade would form a cycle. EF Core makes required relationships cascade by default, so a model like Company → Projects → Tasks plus Company → Employees → Tasks triggers it. Fix it by choosing which path really owns the delete and setting the other relationship to DeleteBehavior.Restrict or DeleteBehavior.NoAction (both emit ON DELETE NO ACTION on SQL Server; ClientCascade is an option if EF Core should delete loaded dependents itself). Then delete the dependents explicitly in the use case, often with ExecuteDelete, or switch to soft delete: an IsDeleted flag or DeletedAt column plus a global query filter, so nothing is physically removed. Wide cascades also lock many rows in one transaction, so avoiding them helps performance.
"SQL Server only allows one cascading path into a table. If deleting a
Companycould reachTasksthrough bothProjectsandEmployees, it rejects the secondON DELETE CASCADEwith error 1785 rather than guess the order. EF Core hits this because it makes every required relationship cascade by convention.The fix is a domain decision, not a syntax one: which parent owns the child? Usually
ProjectownsTask, andEmployeeis only an assignee. So I keep cascade onProject → Taskand setEmployee → TasktoDeleteBehavior.Restrict(orNoAction; on SQL Server both generateON DELETE NO ACTION, the difference is only in how EF Core treats tracked entities). Removing an employee then means reassigning or deleting their tasks explicitly in the handler.Often the better answer is not deleting at all. Soft delete marks the row with
IsDeletedorDeletedAt, a global query filter hides it, and history stays intact for audit. Physical cascades over big graphs also hold locks on every child row in one transaction, which is a performance risk."
| Behaviour | SQL generated | What EF Core does with tracked dependents |
|---|---|---|
Cascade |
ON DELETE CASCADE |
Marks them Deleted |
Restrict / NoAction |
ON DELETE NO ACTION |
Throws or leaves FK; you handle it |
ClientCascade |
ON DELETE NO ACTION |
Deletes loaded dependents only |
SetNull |
ON DELETE SET NULL |
Nulls the FK (optional relationships) |
modelBuilder.Entity<TaskItem>()
.HasOne(t => t.Assignee)
.WithMany(e => e.Tasks)
.OnDelete(DeleteBehavior.Restrict);
public DateTimeOffset? DeletedAt { get; set; }modelBuilder.Entity<TaskItem>().HasQueryFilter(t => t.DeletedAt == null);Deleted state into an update that sets DeletedAt.A cascade from Tenant deleted [~2 million] rows in one transaction and blocked writes for [4 minutes]; we moved to soft delete plus a nightly batched purge with ExecuteDelete in chunks of [5,000].
Checks practical knowledge of SQL Server cascade rules.
Last updated 23 Nov 2026.