EntityFrameworkcore 报错 json转换无限循环嵌套循环处理 Self referencing loop detected with type 或 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.
网上各种方法看不懂 ,小白喜欢一把梭.. 能解决问题就行~~~ 手动把循环终结掉!
var data = Context.商品
.Include(it => it.商品分类).OrderByDescending(it => it.商品id)
.Skip((pageindex - 1) * pagesize).Take(pagesize)
.ToList();
data.ForEach(it => it.商品分类.商品s = new List<商品>());//重点这2行
var ndata = JsonConvert.DeserializeObject<List<商品>>(JsonConvert.SerializeObject(data));//重点这2行
return Ok(new { success = true, data= ndata, message = "", code = 20000, total = Context.商品.ToList().Count });