我有一个使用 .Net Core 的新项目。这是一个 WebAPI 项目。我的模型有一个单独的项目。
在 WebAPI 项目中,在 Controller 中,我有这样的东西:
// GET: api/questions
[HttpGet]
public IEnumerable<Question> GetQuestions()
{
return _context.Questions
.Include( i => i.QuestionType );
}
当我调用 http://localhost:55555/api/questios/
时,它只返回第一条记录,然后是此错误消息:
Recv 失败:连接已重置
如果我删除 Include
部分并只返回 _context.Questions
,它工作得很好!
我的代码有什么问题?
最佳答案
我找到了答案。感谢所有提供帮助的人。
我根据 Loading related data 添加了 json 选项
If you are using ASP.NET Core, you can configure Json.NET to ignore cycles that it finds in the object graph. This is done in the ConfigureServices(...) method in Startup.cs.
services.AddMvc()
.AddJsonOptions(
options => options.SerializerSettings.ReferenceLoopHandling
= Newtonsoft.Json.ReferenceLoopHandling.Ignore );
关于c# - .Net Core WebAPI 连接重置,当我的 Controller 中有 "include"时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44322809/