我有 Asp.Net core 3.1 Web Api,其中复杂的对象应该由 Json 之类的操作返回,问题是返回的对象不包含子对象列表:
对象下方:
public class DepartementViewModel
{
public int Dep_ID { get; set; }
public string Dep_Name { get; set; }
public List<BasicEmpViewModel> listEmployees = new List<BasicEmpViewModel>();
}
Run Code Online (Sandbox Code Playgroud)
和行动
[HttpGet]
public async Task<ActionResult<IEnumerable<DepartementViewModel>>> GetDepartement()
{
IRepository IRepos = new DepartementRepository(_context);
IList<DepartementViewModel> ilIst = await IRepos.GetList();
return Ok(ilIst);
}
Run Code Online (Sandbox Code Playgroud)
存储库 GetList 函数
public async Task<IList<DepartementViewModel>> GetList()
{
IList<DepartementViewModel> listDept = new List<DepartementViewModel>();
listDept = await(from dept in _context.Departement
orderby dept.Dep_ID ascending
select new DepartementViewModel
{ …Run Code Online (Sandbox Code Playgroud)