这是我的ASP.NET CORE WEB API方法
[HttpGet]
[Route("schooltypegroups")]
[Produces("application/json")]
[SwaggerOperation("GetSchoolTypeGroups")]
[SwaggerResponse(400, "Bad input parameter")]
[SwaggerResponse(404, "Not found")]
[SwaggerResponse(500, "Internal server error")]
public async Task<IActionResult> GetSchoolTypeGroups()
{
try
{
var devicetypegroups = await _context.SchoolTypeGroups
.Include(b => b.SchoolTypes)
.Include(p => p.Students)
.ThenInclude(student=> student.StudentGroup)
.ToListAsync();
//Now, studenttypegroups is having all proper data
return Ok(studenttypegroups);
//But returned Null child entities
//Student and StudentGroup is empty in json response like this []
}
catch (Exception exception)
{
return new ServerErrorResult();
}
}
调试时,我在studenttypegroups
中看到了所有正确的值。
但是,返回的JSON对于子实体具有空值。!!
我想念什么吗?
我的猜测
我在.net框架中使用ResponseType
属性。但是我在asp.net代码中看不到它
Json输出显示Students
为空
我认为这是延迟加载问题,.net核心https://github.com/aspnet/EntityFrameworkCore/issues/3797中未实现