'Entity Framework code-first many-to-many relation "may cause cycles"

I have a class that has a many-to-many relation (with some additional relation information) to instances of the same class, like this:

public class Aaa
{
    [Key]
    [MaxLength(25)]
    public string Handle { get; set; } = null!;
}

public class Bbb
{
    [Key]
    [MaxLength(25)]
    public string Handle { get; set; } = null!;

    [Required]
    [Index]
    [MaxLength(25)]
    public string FromAaaHandle { get; set; } = null!;

    [Required]
    [Index]
    [MaxLength(25)]
    public string ToAaaHandle { get; set; } = null!;

    public int SomeOtherRelationStuff { get; set; }

    [ForeignKey("FromAaaHandle")]
    public virtual Aaa FromAaa { get; set; } = null!;

    [ForeignKey("ToAaaHandle")]
    public virtual Aaa ToAaa { get; set; } = null!;
}

That results in an Microsoft.Data.SqlClient.SqlException telling me that the foreign key constraints "may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints"

Whats the problem here? Removing an entry from table Bbb should not have any impact on table Aaa. Removing an entry from Aaa might cause entries to be removed from Bbb but should have no impact on other entries in Aaa. I don't see any cycles



Solution 1:[1]

"may cause cycles or multiple cascade paths." Here Aaa would cascade to all the Bbb's referencing it as FromAaa or ToAaa. This is multiple cascade paths, and isn't allowed.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Browne - Microsoft