我有一系列代表文件夹和文件的对象。文件夹当然可以有一组文件,但它们也可以有子文件夹。文件夹有一个指向父文件夹的引用,这可能是问题的起源。此外,文件夹可以有与之关联的图标。
public class Folder
{
[Key]
public int FolderId { get; set; }
public string FolderName { get; set; }
public int ParentFolderId { get; set; }
public virtual Folder ParentFolder { get; set; }
public int IconId { get; set; }
public virtual Icon Icon { get; set; }
public virtual ICollection<FileInformation> FileInformations { get; set; }
public virtual ICollection<Folder> Folders { get; set; }
}
public class Icon
{
[Key]
public int IconId { get; set; }
public string IconUrl { get; set; }
public string Description { get; set; }
}
当我运行应用程序并尝试获取图标列表时,出现以下错误信息:
*引用关系将导致不允许的循环引用。[ 约束名 = FK_Folder_Icon_IconId ]*
我不确定这里是什么循环引用。Folder只有一次引用Icon,而Icon根本没有引用folder。
一个问题是,我不确定如何正确地将ParentFolderId映射回父文件夹的FolderId。
有任何想法吗?