简体   繁体   English

WebAPI 2返回空对象列表

[英]WebAPI 2 Returns Empty List of Objects

I have this action that is supposed to return a list of students 我有这个动作,应该会传回学生名单

[HttpGet("GetAllStudentsByYear/{year}")]
public IActionResult GetAllStudentsByYear(int year)
{
    using (var db = new StudentsCFD())
    {
        List<student> stud = (from std in db.student 
                              join c in db.cppsas 
                                on std.cppsa_id equals c.cppsa_ID 
                              where c.school_yr == year 
                              select std).ToList();
        return Ok(stud);
    }
}

I am one hundred percent certain stud is not null , it has 28 objects when debugging. 我百分之一百确定螺柱不是null ,调试时有28个对象。 However my output when called looks like this. 但是,我的输出在调用时如下所示。

[
  {}
]

Can you directly return stud? 您可以直接返回螺柱吗? If yes then try it once. 如果是,则尝试一次。 eg return stud; 例如return stud; And if return type IActionResult gives error make it dynamic 如果返回类型IActionResult给出错误,则将其IActionResult dynamic

adding db.Configuration.ProxyCreationEnabled = false before the linq worked. 在linq工作之前添加db.Configuration.ProxyCreationEnabled = false It looks like it was a circular or large referencing of foreign keys. 看起来它是外键的循环引用或大型引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM