I'm surprised EF Core even allowed this
.HasMany(p => p.Dependencies)
.WithMany(p => p.Dependencies)
(using one and the same collection in for both sides of the relationship) without reporting an error.
Many-to-many require 2 collection navigation properties - one for each side of the relationship. So even though this is self referencing relationship, it still requires 2 separate collection navigation properties bound to the corresponding join entity FKs. e.g.
public virtual List<PackageType> ChildDependencies { get; set; } = new List<PackageType>();
public virtual List<PackageType> ParentDependencies { get; set; } = new List<PackageType>();
and
.HasMany(p => p.ChildDependencies) // -> j.PackageId
.WithMany(p => p.ParentDependencies) // -> j.DependencyId
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…