I have a table that should refer to the same table. But when I try to update the database schema, it throws me this error:
When i try to update the schema, PMC throws this error:
System.Data.SqlClient.SqlException (0x80131904): Introducing FOREIGN KEY constraint 'FK_Directory_Directory_SubOfId' on table 'Directory' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
I tried setting ON DELETE to CASCADE but nothing, still the same error. I do not know how to set NO ACTION because mapping does not offer this option.
What with this?
Entity:
public class Directory : BaseEntity
{
public int ID { get; set; }
public int? SubOfId { get; set; }
[ForeignKey("SubOfId")]
public Directory SubOf { get; set; }
public virtual ICollection<ImageDirectory> ImageDirectory { get; set; }
}
Model builder:
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
...
builder.Entity<Directory>().HasOne(e => e.SubOf).WithOne().HasForeignKey<Directory>(a => a.SubOfId).OnDelete(DeleteBehavior.Cascade);
}