gpt4 book ai didi

c# - ASP.Net Core 1.1 解决方案中检测到自引用循环

转载 作者:行者123 更新时间:2023-11-30 14:23:41 26 4
gpt4 key购买 nike

虽然我关注了文章here我不断收到错误

self referencing loop detected for property '...' with type '...'. Path '[4]....[0]'.

我已将此添加到我的 Startup.cs:

services.AddMvc()
.AddJsonOptions(opt =>
opt.SerializerSettings.ReferenceLoopHandling =
ReferenceLoopHandling.Ignore
);

还有什么可能导致引用回路错误?

编辑:回答评论中的问题...受影响的类是:

public partial class GuidingSymptom
{
public GuidingSymptom()
{
VideosGuidingSymptoms = new HashSet<VideosGuidingSymptoms>();
}
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[MaxLength(70)]
[Required]
public string Name { get; set; }
public string Description { get; set; }

public int SeverityId { get; set; }
public int? DiagnoseId { get; set; }

[InverseProperty("GuidingSymptom")]
public virtual ICollection<VideosGuidingSymptoms> VideosGuidingSymptoms { get; set; }
[ForeignKey("DiagnoseId")]
[InverseProperty("GuidingSymptom")]
public virtual Diagnose Diagnose { get; set; }
[ForeignKey("SeverityId")]
[InverseProperty("GuidingSymptom")]
public virtual GuidingSymptomSeverity Severity { get; set; }
}

public partial class VideosGuidingSymptoms
{
public int VideoId { get; set; }
public int GuidingSymptomId { get; set; }

[ForeignKey("GuidingSymptomId")]
[InverseProperty("VideosGuidingSymptoms")]
public virtual GuidingSymptom GuidingSymptom { get; set; }
[ForeignKey("VideoId")]
[InverseProperty("VideosGuidingSymptoms")]
public virtual Video Video { get; set; }
}

最佳答案

我找到了添加的解决方案

[JsonIgnore]

受影响属性的注释。但是,我预计在使用 ReferenceLoopHandling.Ignore

时不需要这样做

关于c# - ASP.Net Core 1.1 解决方案中检测到自引用循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44249667/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com