码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2020-01-05 22:36:24      阅读:513      评论:0      收藏:0      [点我收藏+]

标签:col   parentId   was   text   ros   div   pos   rto   soft   

 

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

 

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

标签:col   parentId   was   text   ros   div   pos   rto   soft   

原文地址:https://www.cnblogs.com/tiandidao/p/12153704.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!