当前位置:首页 > Web开发 > 正文

ef core 自引用类 报错System.Text.Json.JsonException: A possible ob

2024-03-31 Web开发

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....

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/32213.html