以JSON格式返回Object时缺少值

时间:2019-01-06 15:07:24

标签: c# json entity-framework asp.net-web-api entity-framework-6

这是我的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为空

enter image description here

我认为这是延迟加载问题,.net核心https://github.com/aspnet/EntityFrameworkCore/issues/3797中未实现

0 个答案:

没有答案