【发布时间】:2016-09-15 04:39:29
【问题描述】:
环境:
- .net 4.6 1.0.0-rc1-update2
- Entity Framework 核心 rc final。
我的 API 控制器抛出了这个异常:
应用程序引发了未处理的异常。 Newtonsoft.Json.JsonSerializationException:为“Blog.Model.Site”类型的属性“Site”检测到自引用循环。路径“[0].Menus[0]”。
如何实施此处建议的修复: JSON.Net Self referencing loop detected
据我所知,EF core 没有实现延迟加载或代理创建。
我的控制器只返回这个查询生成的集合:
public async Task<List<Site>> GetActiveSites()
{
var query = db.Sites.Where(x => x.Active)
.Include(x => x.Menus)
.ThenInclude(m => m.MenuContentItems)
.ThenInclude(x => x.ContentItem);
return await query.ToListAsync();
}
地点:
- 站点(1) - 菜单(*)
- 菜单(1) - MenuontentItem(*)
- MenuContentItem(*) - ContentItem(1)
【问题讨论】:
-
stackoverflow.com/questions/17313632/… 查看 Stewart Hou 提供的答案。
-
您找到了实际的解决方案吗?
-
@Drakoumel 是的,请参阅上面评论中的链接。
-
你可以看看我在 “Self Referencing Loop Detected” exception with JSON.Net 页面上的回答。
标签: entity-framework asp.net-web-api json.net