ef core 自引用类 报错System.Text.Json.JsonException: A possible object cycle was detected which is not supported....


 

ef core 创建自引用灰了了

 
public class Menu:IEntity
{
    public int Id { get; set; }
    public string text { get; set; }
    public bool group { get; set; }
    public bool shortout_root { get; set; }
    public string link { get; set; }
    public string icon { get; set; }
    public bool linkExact { get; set; }
    public virtual List<Menu> children { get; set; }
     public virtual  int? parentId { get; set; }
     public virtual  Menu? parent { get; set; }
    public List<UserMenu> UserMenu { get; set; }
}
 

报错:System.Text.Json.JsonException: A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32

检测到不支持的可能对象循环。这可能是由于周期或物体深度大于最大允许深度32。

 

解决:添加 Microsoft.AspNetCore.Mvc.NewtonsoftJson 包后正常,但引用的深度就比较深了

id: 8
text: "Test"
group: false
shortout_root: false
link: "Test"
icon: null
linkExact: false
children: null
parentId: 5 parent: {id: 5, text: "CMS", group: false, shortout_root: false, link: null, icon: "anticon anticon-skin",…} id: 5 text: "CMS" group: false shortout_root: false link: null icon: "anticon anticon-skin" linkExact: false children: [{id: 6, text: "CMS列表", group: false, shortout_root: false, link: "/cms/cmslist", icon: null,…},…] 0: {id: 6, text: "CMS列表", group: false, shortout_root: false, link: "/cms/cmslist", icon: null,…} id: 6 text: "CMS列表" group: false shortout_root: false link: "/cms/cmslist" icon: null linkExact: false children: null parentId: 5 userMenu: null
1: {id: 7, text: "模块列表", group: false, shortout_root: false, link: "cms/modulelist", icon: null,…} id: 7 text: "模块列表" group: false shortout_root: false link: "cms/modulelist" icon: null linkExact: false children: null parentId: 5 userMenu: null parentId: 2 parent: {id: 2, text: "业务", group: true, shortout_root: false, link: null, icon: null, linkExact: false,…} id: 2 text: "业务" group: true shortout_root: false link: null icon: null linkExact: false children: [] parentId: null parent: null userMenu: null userMenu: null userMenu: null

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM