Database in my project includes table with cycle link:
Here's the entity class with fluent configuration:
public class ReportFolder
{
public Guid Id { get; set; }
public string Name { get; set; }
public Guid? ParentFolderId { get; set; }
public virtual ReportFolder ParentFolder { get; set; }
public virtual List<ReportFolder> ChildFolders { get; set; }
}
public class ReportFolderConfiguration : IEntityTypeConfiguration<ReportFolder>
{
public void Configure(EntityTypeBuilder<ReportFolder> builder)
{
builder.HasKey(c => c.Id);
builder.Property(c => c.Id).ValueGeneratedOnAdd();
builder.Property(c => c.Name).IsRequired().HasMaxLength(100);
builder.HasOne(c => c.ParentFolder)
.WithMany(c => c.ChildFolders)
.HasForeignKey(c => c.ParentFolderId)
.OnDelete(DeleteBehavior.SetNull);
builder.HasIndex(c => c.Name);
}
}
Problem: I catch error when trying to update database via migration:
System.Data.SqlClient.SqlException (0x80131904): Introducing FOREIGN KEY constraint 'FK_ReportFolders_ReportFolders_ParentFolderId' on table 'ReportFolders' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
User contributions licensed under CC BY-SA 3.0