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